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 one: use 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:
require('smarty/Smarty.class.php');
$t = new Smarty ;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//The fetch() here is to get The function that outputs 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);
?>
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);
?>
The above introduces the traceroute principle and the PHP dynamic to static principle, including the traceroute principle. I hope it will be helpful to friends who are interested in PHP tutorials.