As far as I know, there are two ways to use PHP to output static pages. One is to use template technology, and the other is to use ob series functions. Both methods look similar, but in fact they are different.
The first way: using templates . There are currently many PHP templates, including the powerful smarty and the simple and easy-to-use smarttemplate. Each of their templates has a function to get the output content. The way we generate static pages is to use this function. The advantage of using this method is that the code is clearer and more readable.
Here I use smarty as an example to illustrate how to generate a static page
Copy the code The code is as follows:
php
require('smarty/Smarty.class.php');
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//The fetch() here is the function to get the output content. Now in the $content variable, is the content to be displayed
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
? >
The second method : Use the ob series of functions. The functions used here are mainly ob_start(), ob_end_flush(), ob_get_content(), where ob_start() means to open the browser buffer. After opening the buffer, all non-file header information from the PHP program will not be sent. Instead, it is stored in the internal buffer until you use ob_end_flush(). The most important function here is ob_get_contents(). The function of this function is to obtain the contents of the buffer, which is equivalent to the fetch() above. The reason Same. Code:
Copy code The code is as follows:
ob_start();
echo "Hello World! ";
$content = ob_get_contents();//Get all the content output by the php page
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>
http://www.bkjia.com/PHPjc/317259.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317259.htmlTechArticleAs far as I know, there are two ways to use PHP to output static pages. One is to use template technology , the other is to use the ob series function. Both methods look similar, but in fact...