Home >Backend Development >PHP Tutorial >Detailed explanation of three ways to write nested HTML in PHP
Generally speaking, there are two mixed writing methods, one is HTML with PHP, written
<?php ?><br>
; the other is PHP sets HTML and writes
<?php echo ?><br>
. If PHP enables short tag writing, it can also be written as
<?=$item['RAND']?><br>
. There is also a different way Commonly used mixed writing methods are as follows:
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>
List two ways of writing a piece of code in the project:
<?php <br/>if($resitem['PREVIEW']){<br/>echo $resitem['PREVIEW'];<br/>} else {<br/>echo "static/images/bg72.png";<br/>}<br/>?><br>
Writing method two:
<?php <br/>if($resitem['PREVIEW']): ?> <?=$resitem['PREVIEW']?><?php else: ?>static/images/bg72.png<?php endif ?><br>
The summary is complete; thank you all for reading, I hope you will benefit from it.
For more information, please refer to the official document http://www.php.net/manual/zh/control-structures.if.php
This article is reproduced from: https://blog.csdn. net/freshlover/article/details/9279527
Recommended tutorial: "php tutorial"
The above is the detailed content of Detailed explanation of three ways to write nested HTML in PHP. For more information, please follow other related articles on the PHP Chinese website!