Home  >  Article  >  Backend Development  >  How to change html tags in php

How to change html tags in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-10 09:20:293671browse

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 html tags in php

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 = &#39;我最近在读廖一梅的《像我这样笨拙的生活》&#39;;
//读取test.html文件中的所有内容,并以字符串的形式返回$fileContent = file_get_contents(&#39;test.html&#39;);
//从$fileContent字符串中把{$content}替换为$content的内容,并返回字符串$str = str_replace(&#39;{$content}&#39;,
$content,$fileContent);//最后输出内容echo $str;
?>

3. Finally, through page access, you can access the content. The results are as follows:

How to change html tags in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn