<?
if($id == 2) {
?>
html goes here
<?
}
else {
?>
if id is not 2 then something goes here
<?
}
?>
不学聪明怎么把php+html写在一个文件里更漂亮?
最佳答案
您可以使用 PHP's alternative syntax for control structures :
<? if ($id == 2): ?>
<h2>some html</h2>
<? else: ?>
<h2>another html chunk</h2>
<? endif ?>
请注意 short_open_tags是一个需要显式启用的 php.ini 指令,否则你将不得不编写 <?php
每次。
关于php - 如何把php+html写在一个文件里更漂亮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2795847/