包含后的PHP解析文件
以下是我想做的:包含后的PHP解析文件,php,Php,以下是我想做的: <? include 'header.php' ?> some html <? include 'footer.php' ?> 一些html 在header.php中 <? //bunch of code if (something){ //some stuff here, but no close brace ?> 在footer.php中 <? } //close the if brace ?> 这可能吗?我
<? include 'header.php' ?>
some html
<? include 'footer.php' ?>
一些html
在header.php中
<? //bunch of code
if (something){
//some stuff here, but no close brace
?>
在footer.php中
<? } //close the if brace ?>
这可能吗?我不断收到解析错误
谢谢。不,你不能那样做。您的方括号都需要在同一个文件中 如果希望有条件地包含HTML,请将逻辑放在
include
s header.php和footer.php文件中
一些html
其他一些html
另外,不要使用ASP样式(
)短打开标记。他们被弃用了。您仍然可以使用
输出变量等
我使用
header.php
&footer.php
的大部分时间是为网页生成文本页眉
&页脚
。php逻辑仅限于文件本身。不能在文件之间扩展它。虽然您可能已经知道,include文件甚至需要它们的
标记,即使这些标记中已经包含include调用。从什么时候开始不推荐使用短标记了?我同意不应该使用它们,但它们肯定不会从发动机上拆下。你有资料支持吗?
<?php include 'header.php' ?>
<?php if (/* something */): ?>
some html
<?php else : ?>
some other html
<?php endif; ?>
<?php include 'footer.php' ?>