1
从tuxradar.com:PHP输出文本WITHOUT echo/print?
实施例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
,据我所知,不应使用print
或echo
的PHP解析器来理解一堆单词。那么为什么当一堆“病房”被另外一组<?php ?>
标签分开时,它实际上会被打印?
我想我错过了一些我想了解的核心。
@frrlod:这是一个非常普遍的做法,可以导致_very漂亮的代码。如果你需要在纯HTML中输出变量,可以考虑这样做:'<?= $ variable?>'或'<?php echo $ variable; ?>'。这都是关于可读性的。 –
@Kristy服务器将其解释为纯文本。反正浏览器不会读PHP。 – Anujan