我是php的初学者,想在这里得到你们的帮助, 我有一个php include标签,我希望它在一个html标签和两者之间的php if标签...我试过这个并给erro,请帮忙。
<?php if ($menu->getActive() == $menu->getDefault()) ?>
<section class="content">
<?php { include '_include-content.php'; } ?>
</section>
<?php endif ?>
答案 0 :(得分:2)
请执行此操作[在 HTML
声明中附上 echo
内容。]
<?php
if ($menu->getActive() == $menu->getDefault())
{
echo "<section class='content'>";
include '_include-content.php';
echo "</section>";
}
?>
答案 1 :(得分:1)
根据
http://www.php.net/manual/en/control-structures.if.php
http://www.php.net/manual/en/control-structures.alternative-syntax.php
<?php if ($menu->getActive() == $menu->getDefault()): ?>
<section class="content">
<?php include '_include-content.php'; ?>
</section>
<?php endif ?>
或
<?php if ($menu->getActive() == $menu->getDefault()){ ?>
<section class="content">
<?php include '_include-content.php'; ?>
</section>
<?php } ?>
应该可以正常工作..
答案 2 :(得分:1)
PHP if函数的工作原理如下
if (conditions) {
// do sth
}
或
if (conditions):
// do sth
endif;
你使用括号和endif进行混音 所以对于你的问题,试试:
<?php if ($menu->getActive() == $menu->getDefault()) { ?>
<section class="content">
<?php include '_include-content.php'; ?>
</section>
<?php } ?>
我建议使用这种语法,因为它通常被使用。
对于您的问题,请参阅http://php.net/manual/en/control-structures.alternative-syntax.php
中的说明注意:不支持在同一控制块中混合语法。
答案 3 :(得分:1)
<?php if ($menu->getActive() == $menu->getDefault()){ ?>
<section class="content">
<?php include '_include-content.php'; ?>
</section>
<?php } ?>