【发布时间】:2010-04-21 02:36:33
【问题描述】:
我知道不可能为任何给定的 PHP 设置样式,但我知道可以设置 PHP 为您提供的输出 HTML 的样式。我想知道是否有任何方法可供我使用,使我能够设置 IF ELSE 语句的输出样式。
if ($result != false) {
print "Your entry has successfully been entered into the blog.";
}
【问题讨论】:
我知道不可能为任何给定的 PHP 设置样式,但我知道可以设置 PHP 为您提供的输出 HTML 的样式。我想知道是否有任何方法可供我使用,使我能够设置 IF ELSE 语句的输出样式。
if ($result != false) {
print "Your entry has successfully been entered into the blog.";
}
【问题讨论】:
只需在打印的字符串中使用 HTML。不需要花哨的东西。
if ($result != false) {
print "<p class=\"success\">Your <strong>entry</strong> has <a href=\"http://example.com/\">successfully</a> been entered into the blog. <img src=\"smileyface.png\" alt=\"Smiley face\" /></p>";
}
【讨论】:
你是说这个吗?
if ($result != false) {
print "<span style='color:#ff0000'>Your entry has successfully been entered into the blog.</span>";
}
【讨论】:
我喜欢做的,只是为了让生活变得简单,就是在我的页面中在 HTML 和 PHP 之间切换。例如,
<?php if ($fooSuccess = true) {?>
<p><span style="color: green;">Success!</span></p>
<?php } else {?>
<p><span style="color: red;">Error!</span></p>
<?php } ?>
【讨论】:
然后你需要打印 HTML。
if ($result != false) {
print "<b>Your entry has successfully been entered into the blog.</b>";
}
甚至
if ($result != false) {
print "<div class='Style1'>Your entry has successfully been entered into the blog.</div>";
}
【讨论】: