This article will share with you the sample code for dynamically generating static HTML pages in PHP. For more information, see temp.html.
The Code is as follows:
{Penglig_site_title}
Test. php
The Code is as follows:
Header ('content-type: text/html; charset = UTF-8 '); // prevents generated page garbled characters
$ Title = "PHP dynamic generation of static HTML page _ script house"; // defines Variables
$ Url = "http://www.php.net /";
$ Temp_file = "temp.html"; // temporary file, which can also be a 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 content
$ Str = str_replace ("{penglig_site_url}", $ url, $ str); // replace content
Fclose ($ fp );
$ Handle = fopen ($ dest_file, "w"); // write mode to open the file to be written
Fwrite ($ handle, $ str); // write the replaced content into the generated HTML file.
Fclose ($ handle); // close open files and release file pointers and related buffers.
Echo "script" alert ('generated successfully'); window. location. href = '". $ dest_file."'; script ";
?>
Run test. php. The specific code is modified based on actual needs.