Php is used to generate static files. most of the files are generated by replacing them with templates. for example, if I define {A} as A tag in php, I only need to use fopen to read the template file, then replace {A} with replace to generate A static html file instance for PHP... php is used to generate static files. most of the files are generated by replacing them with templates. for example, if I define {A} as A tag in php, I only need to use fopen to read the template file, replace {A} with replace to generate A static html file instance for PHP.
1. The following is a template method!
Simply write the template into a file and save it as HTML.
2. generate html file names by time
The file pointer points to the beginning and sets the length of the original file to 0. If the file does not exist,
Create a new file.
3. The following is a method for converting file names.
In this way, 93e. php can be converted to a static HTML file. Note that the files to be converted cannot contain ob_end_clean (); and ob_start (); statements, and the directory must have write permission.
The above three methods generate html pages and update them every time. below we can use dynamic page cache technology to instance html + php pages. this method is better than above.
First set. htaccess file, convert Dynamic Call parameters to static html url address, for example, the file under the post Directory, forward to the wp-post.php file in the root directory, the added statement is similar:
RewriteRule ^ post/(%a-z0-9-%}.html) $ wp-post.php? $1 $2
Then modify the wp-post.php file and add the following PHP code at the beginning of the file:
Time () // determines whether the last HTML file was generated for more than 1 hour. if not, the file content {echo (file_get_contents (HTML_FILE) is output directly )); exit (0) ;}}?>
Then there is the existing PHP code, and the following PHP code is added at the end of the current code:
");$buffer = ob_get_flush();$fp = fopen(HTML_FILE, "w");if ($fp) { fwrite($fp, $buffer . HTMLMETA); fclose($fp);}?>
Now, check your static HTML page. if a comment line appears at the end of the page, it means that a static HTML file has been created successfully.
Address:
Reprinted at will, but please attach the article address :-)