In the development of PHP Web site for the promotion and SEO needs, need to site for the whole station or local static processing, PHP generated static HTML page has a variety of methods, such as the use of PHP templates, caching, such as the implementation of the page static, today in the PHP instance tutorial form to discuss the method of generating static pages PHP. Page static method, divided into two kinds, one is pseudo static, is URL rewrite, one is you really static. Here's a description of how the page is static in PHP.
What is PHP static
The simple understanding of PHP static is to make the site generated page in the form of static HTML display in front of visitors, PHP static separation of pure static and pseudo static, the difference between the two is that PHP generated static page processing mechanism is different.
How PHP generates a static HTML page
1, the use of PHP templates to generate static pages
PHP templates to achieve static is very convenient, such as the installation and use of PHP Smarty implementation of the Web site static.
2, using PHP file read and write function to generate static page
PHP generates static page instance code
3, use the PHP output control function (output controls) to generate a static page
Output control functions, which use and control caching to generate static HTML pages, also use the PHP file read-write function.
PHP generates static page instance code
We know that the use of PHP for Web site development, the general results directly output to the browser, in order to use PHP to generate static pages, you need to use the output control function to control the buffer cache to obtain the contents of the buffer, and then output to the static HTML page file to achieve static Web site.
PHP generated a static page thinking: First open the cache, and then output the HTML content (you can also include HTML content in the form of file), and then get the contents of the cache, empty the cache through the PHP file read and write function to write the cached content to the static HTML page file. PHP file reading and writing tutorial?
The process of getting the cached content of the output to generate a static HTML page requires three functions: Ob_start (), ob_get_contents (), Ob_end_clean ().
Knowledge Points:
1, Ob_start function is generally used to open the cache, pay attention to the use of Ob_start can not have any output, such as spaces, characters and so on.
2, the Ob_get_contents function is mainly used to get the contents of the cache to return as a string, note that this function must be called before the Ob_end_clean function, otherwise the cached content is not obtained.
3, the Ob_end_clean function is mainly empty the contents of the cache and turn off the cache, success returns TRUE, Failure returns false
There are many applications for PHP output control functions, which will be launched in the future.
At this point, the use of PHP to generate static HTML page to achieve static site method is introduced, according to the actual situation and requirements you can choose different static method.
- ?
- $out 1 = "
- <body> Welcome to visit the PHP website Development Tutorial Network www.leapsoul.cn, this article mainly introduces the PHP Web page static method
- </body>
- $fp = fopen ("leapsoulcn.html", "w");
- if (! $fp)
- {
- echo "System Error";
- Exit ();
- }
- else {
- Fwrite ($fp, $out 1);
- Fclose ($FP);
- echo "Success";
- }
- ?>
- ?
- Ob_start ();
- echo "
- "
- "<title>php website static tutorial </title>".
- "
- "<body> Welcome to visit the PHP website Development Tutorial Network www.leapsoul.cn, this article mainly introduces the PHP Site page static method </body>".
- "
- $out 1 = ob_get_contents ();
- Ob_end_clean ();
- $fp = fopen ("leapsoulcn.html", "w");
- if (! $fp)
- {
- echo "System Error";
- Exit ();
- }
- Else
- {
- Fwrite ($fp, $out 1);
- Fclose ($FP);
- echo "Success";
- }
- ?>