PHP 并不是我真正选择的语言,也就是说我记得看到过 php if
被使用如下:
<?php
if (blah) {
?>
// loads of html and js that doesn't need to be escaped since we closed
// the php already with "?>"
<?php
}
?>
或者类似的东西。我不知道它叫什么,谷歌搜索 php 如果没有帮助。
这种技术叫什么?它的正确语法是什么?
最佳答案
它可以像您在问题中发布的那样使用,或者像这样(我更喜欢):
<?php
if(blah):
?>
// loads of html and js that doesn't need to be escaped since we closed
// the php already with "?>"
<?php
endif;
?>
这最常见于不执行任何逻辑的模板,仅使用简单的 if
和 loops
,例如:
<?php foreach($something as $test): ?>
<p><?php echo $test; ?></p>
<?php endforeach; ?>
关于php 是否包含 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10350457/