Template file template.htm:
Copy code The code is as follows:
php file:
Copy code The code is as follows:
//The Replace function is used to read from the template file Replace the keywords in the content with the content in the variable
function Replace($row)
{
//Define the variable used for replacement
$title = "Article Title";
$ body = "This is the body of the article";
//Replace the keywords in the parameters
$row = str_replace("%title%", $title, $row);
$row = str_replace(" %body%", $body, $row);
//Return the replacement result
return $row;
}
//Template file pointer
$f_tem = fopen(" template.htm","r");
//Generated file pointer
$f_new = fopen("new.htm","w");
//Loop to read the template file, each Read one line at a time
while(!feof($f_tem))
{
$row = fgets($f_tem);
$row = Replace($row); //Replace the read content Keywords in
fwrite($f_new, $row); //Write the replaced content into the generated HTML file
}
//Close the file pointer
fclose($f_new);
fclose($f_tem);
?>
Generate a new html page: new.html
Copy code The code is as follows:
Article title
Article title
This is the body of the article
< /body>
http://www.bkjia.com/PHPjc/320042.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320042.htmlTechArticleTemplate file template.htm: Copy the code as follows: html head title%title%/title /head body H1% title%/H1 hr pre%body%/pre /body /html php file: Copy the code as follows: ?php /...