Template file template.htm:
Copy the code The code is as follows:
%body%
Copy code The code is as follows:
//The Replace function is used to replace the keywords in the content read from the template file with the content in the variable
function Replace( $row)
{
//Define variables for replacement
$title = "Article title";
$body = "Here is the body of the article";
//Replace keywords in parameters
$row = str_replace(" %title%", $title, $row);
$row = str_replace("%body%", $body, $row);
//Return the replaced result
return $row;
}
//Template File pointer
$f_tem = fopen("template.htm","r");
//Generated file pointer
$f_new = fopen("new.htm","w");
//Loop reading template File, read one line at a time
while(!feof($f_tem))
{
$row = fgets($f_tem);
$row = Replace($row); //Replace the keywords in the read content
fwrite($f_new, $row); //Write the replaced content into the generated HTML file
}
//Close the file pointer
fclose($f_new);
fclose($f_tem);
?>
Copy the code The code is as follows:
Here is the body of the article
The above introduces the put your head on my shoulder PHP static implementation code, including the content of put your head on my shoulder. I hope it will be helpful to friends who are interested in PHP tutorials.