Principle of traceroute PHP dynamic to static principle

WBOY
Release: 2016-07-29 08:35:11
Original
1464 people have browsed it

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);
?>


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 the 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);
?>

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template