Home > Article > Backend Development > How to use php and html together
1. Write a class that contains various methods. Different methods correspond to different parts of html. You can use escape symbols to escape double quotes
For example, the following example :
<?php class page{ public function theHead(){ echo "<head> <title>我是title部分啦</title> <meta charset=\"utf-8\"/> </head>"; } public function theBody(){ echo " <div><a href=\"http://www.debugcode.cn\"></a></div> "; $p=<<<PARA <p>我是段落内容我是段落内容我是</p><span>段落内容我是段落内容我是段落内容</span> PARA; echo $p; } }
2. This introduction to the way of using php html code in static files and dynamic files
1. When the file is a static file, such as such.html file, then Multiple 7d5c1acb21d8d3dfe191bfdcfdda5f06 codes can be inserted into different lines in the static file. In this way, the output can be controlled through dynamic code, loop structures can be used, and so on. This kind of file is mostly used as a template, such as the template to be introduced below.
2. When the format of the file is php, such as such.php file, the php interpreter will actively interpret the file. A small amount of html code can also be written in such a file, such as:
<?php $a=2;?> <div><span>我是php文件中的html代码部分</span></div> <?php if($a==2){ ?> <span>当前面的变量$a的值等于2的时候我(一段html静态代码)就被输出了</span> <?php }else{ ?> <span>当前面的变量$a不等于2的时候我就输出了呗。。。</span> <?php }?>
3. By defining a static html template file, such as exampleStatic.html, this template file has several 79184d89c68e7248f3e40700b013c63b code paragraphs inserted. Then import the exampleStatic.html file in another example.php file (require_once "specify file path";
Pay attention to the position of this line of code, because the imported file is a template and there are many php variables in it. , these variables are all uncertain values, and these variables will be used in the example.php file, so before importing the template file, define the required variables in the example.php file, so that the template can be Change the php variable in to the desired value.
Recommended tutorial: PHP video tutorial
The above is the detailed content of How to use php and html together. For more information, please follow other related articles on the PHP Chinese website!