Php can use the built-in function preg_replace to replace arrays in batches. However, regular expression replacement is inefficient and inconvenient to use. For more information, see the php manual. If you have any need, refer.
Php can use the built-in function preg_replace to replace arrays in batches. However, regular expression replacement is inefficient and inconvenient to use. For more information, see the php manual. If you have any need, refer.
This Code demonstrates how php generates static pages through custom template pages and custom tags. The principle is very simple, that is, replacing 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.