这就是我想要做的事情:
<? include 'header.php' ?>
some html
<? include 'footer.php' ?>
在header.php中...
<? //bunch of code
if (something){
//some stuff here, but no close brace
?>
在footer.php中....
<? } //close the if brace ?>
这可能吗?我一直在解析错误。
感谢。
答案 0 :(得分:2)
不,你不能这样做。你的括号都需要在同一个文件中。
如果您想要有条件地包含HTML,请将您的逻辑放在include
s header.php 和 footer.php
<?php include 'header.php' ?>
<?php if (/* something */): ?>
some html
<?php else : ?>
some other html
<?php endif; ?>
<?php include 'footer.php' ?>
另外,请勿使用ASP样式(<? ?>
)短开标签。他们被弃用了。您仍然可以使用<?= ?>
输出变量等。