With PHP output static page method, as I know, there are 2 kinds, one is the use of template technology, the other is the OB series function. Both methods look the same, but in fact, they are different.
The first type: using templates。 PHP is now a template can be said to be many, there are powerful smarty, there are easy-to-use smarttemplate and so on. Each of these templates has a function to get the output content. The way we generate static pages is to take advantage of this function. The advantage of this method is that the code is clear and readable.
Here I use Smarty as an example to show how to generate static pages
Copy CodeThe code is as follows: Require (' smarty/smarty.class.php ');
$t = new Smarty;
$t->assign ("title", "Hello world!");
$content = $t->fetch ("templates/index.htm");
Here the fetch () is the function that gets the output content, now inside the $content variable, is to display the content
$fp = fopen ("archives/2005/05/19/0001.html", "w");
Fwrite ($fp, $content);
Fclose ($FP);
?>
The second method of: Use the functions of the OB series. The function used here is mainly Ob_start (), Ob_end_flush (), Ob_get_content (), where Ob_start () is the meaning of opening the browser buffer, after opening the buffer, all non-file header information from the PHP program will not be sent, Instead, it is saved in the internal buffer until you use Ob_end_flush (). The most important function here is ob_get_contents (), the function of which is to get the contents of the buffer, equivalent to the fetch () above, the same reason. Code:
Copy CodeThe code is as follows: Ob_start ();
echo "Hello world!";
$content = Ob_get_contents ();//Get all the contents of the PHP page output
$fp = fopen ("archives/2005/05/19/0001.html", "w");
Fwrite ($fp, $content);
Fclose ($FP);
?>
http://www.bkjia.com/PHPjc/317259.html www.bkjia.com true http://www.bkjia.com/PHPjc/317259.html techarticle with PHP output static page method, as I know, there are 2 kinds, one is the use of template technology, the other is the OB series function. Both methods look the same, but actually ...