【问题标题】:PHP outputting text WITHOUT echo/print? [closed]PHP输出没有回显/打印的文本? [关闭]
【发布时间】:2013-05-26 13:51:33
【问题描述】:

来自 tuxradar.com:

示例 1:

<?php
    if ($foo == $bar) {
        print "Lots of stuff here";
        print "Lots of stuff here";
        print "Lots of stuff here";
        ...[snip]...
        print "Lots of stuff here";
        print "Lots of stuff here";
    }
?>

示例 2:

<?php
    if ($foo == $bar) {
?>
    Lots of stuff here
    Lots of stuff here
    Lots of stuff here
    ...[snip]...
    Lots of stuff here
    Lots of stuff here
<?php
    }
?>

假设$foo = $bar

两者的输出相等。我不明白为什么。示例 2 没有 print/echo,据我了解,如果没有 printecho,PHP 解析器不应该理解一堆单词。那么,当“一堆病房”被另一组&lt;?php ?&gt; 标签分隔时,为什么它实际上会被打印出来,而通常不会呢?

我想我在这里遗漏了一些我想深入了解的东西。

【问题讨论】:

    标签: php html output


    【解决方案1】:

    示例 2 输出文本的原因是您关闭了 PHP 标记。浏览器将其呈现/解释为纯文本。您还可以使用 HTML 格式化文本输出,它会在浏览器中很好地呈现。

    【讨论】:

    • @frrlod:这是一种非常常见的做法,可以使代码看起来非常漂亮。如果您需要以纯 HTML 格式输出变量,请考虑这样做:&lt;?= $variable ?&gt;&lt;?php echo $variable; ?&gt;。一切都是为了可读性。
    • @Kristy 服务器将其解释为纯文本。浏览器无论如何都不会读取 PHP。
    猜你喜欢
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    相关资源
    最近更新 更多