一般来说有两种混合写法,一种是HTML套PHP,写作<?php ?>
;另一种是PHP套HTML,写作<?php echo ?>
,若php开启短标签写法,也可写作=$item['RAND']?>
还有一种不太常用的混合写法如下:easy way to execute conditional html / javascript / css / other language code with php if else:
html code to run if condition is true
html code to run if condition is false
列出项目中的一段代码的两种写法:<?php
if($resitem['PREVIEW']){
echo $resitem['PREVIEW'];
} else {
echo "static/images/bg72.png";
}
?>
写法二:<?php
if($resitem['PREVIEW']): ?> =$resitem['PREVIEW']?><?php else: ?>static/images/bg72.png<?php endif ?>
总结完毕;感谢大家的阅读,希望大家有所收益。
更多可以参考官方文档http://www.php.net/manual/zh/control-structures.if.php
本文转自:https://blog.csdn.net/freshlover/article/details/9279527
推荐教程:《php教程》