Home >Backend Development >PHP Problem >How to change html tags in php
How to change the html tag in php: first create a page and name it [test.html]; then create another page and enter the code on the page [mytest.php]; finally visit the page.
How to change the html tag in php:
1. First create a page and name it: test.html The following
<!ctype html> <html> <head> <meta charset="UTF-8"><title>模板</title> </head> <body>{$content} </body> </html>
requirements: read {$content} and output the content the user wants to output.
2. Next, create another page. The mytest.php code is as follows:
<?php //给$content赋值,且是字符串的形式$content = '我最近在读廖一梅的《像我这样笨拙的生活》'; //读取test.html文件中的所有内容,并以字符串的形式返回$fileContent = file_get_contents('test.html'); //从$fileContent字符串中把{$content}替换为$content的内容,并返回字符串$str = str_replace('{$content}', $content,$fileContent);//最后输出内容echo $str; ?>
3. Finally, through page access, you can access the content. The results are as follows:
Related learning recommendations: php programming (video)
The above is the detailed content of How to change html tags in php. For more information, please follow other related articles on the PHP Chinese website!