php - 如何把php+html写在一个文件里更漂亮?

标签 php html

<?
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/

相关文章:

javascript - 如何在 html5 Canvas 上绘制移动的重复图案

JavaScript Canvas 库很慢,不使用 GPU?

php - symfony 2.8 : id AND uid column in same table

php - 为什么这个 SQL 注入(inject)不起作用?

javascript - 如何在服务器端验证 jquery 中动态创建的控件 - Php

PHP 7.2 - 警告 : count(): Parameter must be an array or an object that implements Countable

html - CSS 百分比不起作用的 3x2 网格

html - 如何使用 HTML5 或/或 Angular8 实现持续时间选择器,小时数超过 24 小时?

html - rails 页脚不粘在页面底部

php - 命名空间 : "use as" global