I know the method of outputting static pages using PHP. One is to use the template technology, and the other is to use the ob series functions. Both methods look similar, but they are actually different.
First: Use templates. At present, PHP templates can be said to be many, including powerful smarty and easy-to-use smarttemplate. Each of these templates has a function to get the output content. We use this function to generate static pages. The advantage of using this method is that the Code is clear and readable.
Here I use smarty as an example to illustrate how to generate static pages.
Copy codeThe Code is as follows: <? Php
Require ('smarty/smarty. class. php ');
$ T = new Smarty;
$ T-> assign ("title", "Hello World! ");
$ Content = $ t-> fetch ("templates/index.htm ");
// Here fetch () Is the function used to obtain the output content. In the $ content variable, it is the content to be displayed.
$ Fp = fopen ("archives/2005/05/19/0001 .html", "w ");
Fwrite ($ fp, $ content );
Fclose ($ fp );
?>
Method 2: Use ob functions. The functions used here are mainly ob_start (), ob_end_flush (), ob_get_content (), where ob_start () indicates to open the browser buffer. After the buffer is enabled, all non-file header information from PHP programs is not sent, but stored in the internal buffer until you use ob_end_flush (). the most important function here is ob_get_contents (). The function is used to obtain the buffer content, which is equivalent to the fetch () above. Code:
Copy codeThe Code is as follows: <? Php
Ob_start ();
Echo "Hello World! ";
$ Content = ob_get_contents (); // Retrieves all the content output on the php page.
$ Fp = fopen ("archives/2005/05/19/0001 .html", "w ");
Fwrite ($ fp, $ content );
Fclose ($ fp );
?>