Template file template.htm:
Copy the Code code as follows:
%title%
%title%
%body%
PHP Files:
Copy the Code code as follows:
The Replace function is used to replace the keywords in the content read from the template file with the contents of the variable
function Replace ($row)
{
Define the variables to replace
$title = "article title";
$body = "Here is the subject of the article";
Replace a keyword in a parameter
$row = Str_replace ("%title%", $title, $row);
$row = Str_replace ("%body%", $body, $row);
Returns the replaced result
return $row;
}
Template file pointer
$f _tem = fopen ("template.htm", "R");
The generated file pointer
$f _new = fopen ("new.htm", "w");
Iterate through a template file, reading one line at a time
while (!feof ($f _tem))
{
$row = fgets ($f _tem);
$row = Replace ($row); Replace keywords in read-in content
Fwrite ($f _new, $row); Writes the replaced content to the generated HTML file
}
Close file pointer
Fclose ($f _new);
Fclose ($f _tem);
?>
Generate a new HTML page: new.html
Copy the Code code as follows:
Article title
Article title
Here is the subject of the article
The above describes the put your head on my shoulder php static implementation code, including put your head on my shoulder aspects, I hope to be interested in PHP tutorial friends helpful.