From 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
,据我所知,没有print
或echo
的PHP解析器不应该理解一堆词。那么,为什么当"一堆病房"被另一组<?php ?>
标签分开时,它实际上会被打印出来,而通常情况下不会?
我想我遗漏了一些我想彻底了解的东西。
示例2输出文本的原因是您关闭了PHP标记。浏览器将其呈现/解释为纯文本。还可以用HTML格式化文本输出,这样在浏览器中就能很好地呈现。