一般来说有两种混合写法,一种是HTML套PHP,写作
<?php ?><br/>
;另一种是PHP套HTML,写作
<?php echo ?><br/>
,若php开启短标签写法,也可写作
<?=$item['RAND']?><br/>
还有一种不太常用的混合写法如下:
立即学习“PHP免费学习笔记(深入)”;
easy way to execute conditional html / javascript / css / other language code with php if else:<br/><?php if (condition):?><br/>html code to run if condition is true<br/><?php else: ?><br/>html code to run if condition is false<br/><?php endif ?><br/>
列出项目中的一段代码的两种写法:
<?php <br/>if($resitem['PREVIEW']){<br/>echo $resitem['PREVIEW'];<br/>} else {<br/>echo "static/images/bg72.png";<br/>}<br/>?><br/>
写法二:
<?php <br/>if($resitem['PREVIEW']): ?> <?=$resitem['PREVIEW']?><?php else: ?>static/images/bg72.png<?php endif ?><br/>
总结完毕;感谢大家的阅读,希望大家有所收益。
更多可以参考官方文档http://www.php.net/manual/zh/control-structures.if.php
本文转自:https://blog.csdn.net/freshlover/article/details/9279527
推荐教程:《php教程》
以上就是详细解说三种PHP嵌套HTML的写法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号