【问题标题】:Styling an If Else Statement设置 If Else 语句的样式
【发布时间】: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 html css


    【解决方案1】:

    只需在打印的字符串中使用 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>";
    }
    

    【讨论】:

    • 不要链接“成功”;而是链接“条目”。
    • @Gumbo 我只是随意添加标签,不考虑上下文来展示它们的用法。
    【解决方案2】:

    你是说这个吗?

    if ($result != false) {
     print "<span style='color:#ff0000'>Your entry has successfully been entered into the blog.</span>";
    }
    

    【讨论】:

      【解决方案3】:

      我喜欢做的,只是为了让生活变得简单,就是在我的页面中在 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 } ?>
      

      【讨论】:

      • 另外,请注意,这将在您页面的正文标记中
      • 所以“简单”是 PHP 和非 PHP 之间的额外行和不和谐的切换?嵌套在这里也很讨厌。
      • 投赞成票不是因为我偏爱这种风格,而是因为基于一次性脚本中的风格差异而投反对票是微不足道且适得其反的。
      • @ceejayoz 是时候放弃意大利面条代码并学习使用模板了;)
      • @ceejayoz 你的笔记 - 是的。但是示例本身比其他答案的丑陋回声要好得多。
      【解决方案4】:

      然后你需要打印 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>";
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-07
        • 1970-01-01
        • 2021-09-14
        • 1970-01-01
        • 2019-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多