Php uses the tag replacement method to generate static pages and php static pages. Php uses the tag replacement method to generate static pages. The php static page code demonstrates how php generates static pages through custom template pages and custom tags. The principle is very simple. php uses tag replacement to generate static pages and php static pages.
This code demonstrates how php generates static pages through custom template pages and custom tags. The principle is very simple, that is, to replace tags on the template page with dynamic data. I hope it will give you some inspiration.
Template.html template file
{site_title} - sharejs.com
Test. php dynamic file
<? Phpheader ('content-type: text/html; charset = utf-8 '); // prevents generated page garbled characters $ title = "PHP dynamic generation of static HTML page _ script sharing "; // define the variable $ url = "http://www.sharejs.com"; $ temp_file = "temp.html"; // temporary file, or the template file $ dest_file = "dest_page.html "; // generated target page $ fp = fopen ($ temp_file, "r"); // read-only open template $ str = fread ($ fp, filesize ($ temp_file )); // read the template content $ str = str_replace ("{penglig_site_title}", $ title, $ str); // replace the content $ str = str_replace ("{penglig_site_u Rl} ", $ url, $ str); // replace content fclose ($ fp); $ handle = fopen ($ dest_file," w "); // write the fwrite ($ handle, $ str) file to be written into; // write the replaced content into the generated HTML file fclose ($ handle ); // Close the opened file and release the file pointer and related buffer echo "script alert ('generated successfully'); window. location. href = '". $ dest_file. "'; script";?>
The above is all the content of this article. I hope you will like it.
The example code demonstrates how php generates static pages through custom template pages and custom tags. The principle is very simple...