Home >Backend Development >PHP Tutorial >Detailed explanation of three ways to write nested HTML in PHP

Detailed explanation of three ways to write nested HTML in PHP

烟雨青岚
烟雨青岚forward
2020-07-15 13:19:354032browse

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[&#39;RAND&#39;]?><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[&#39;PREVIEW&#39;]){<br/>echo $resitem[&#39;PREVIEW&#39;];<br/>} else {<br/>echo "static/images/bg72.png";<br/>}<br/>?><br>

Writing method two:

<?php <br/>if($resitem[&#39;PREVIEW&#39;]): ?> <?=$resitem[&#39;PREVIEW&#39;]?><?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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete