PHP methods for generating static pages _php Tutorial

Source: Internet
Author: User
Tags php web development php website
In the development of PHP Web site for website promotion and SEO needs, need to site or local static processing, PHP generated static HTML page has a number of methods, such as the use of PHP templates, caching and other implementation of the page static, today in PHP as a tutorial to discuss how to generate static page PHP. Page static method, divided into two, one is pseudo-static, is URL rewrite, one is you really static. The following is a description of how pages are statically formatted in PHP.
What is PHP static
PHP static simple understanding is to make the site Generation page in the form of static HTML in front of the visitors, PHP static pure static and pseudo-static, the difference is that PHP generated static page processing mechanism is different.
How PHP generates static HTML pages
1. Generate static pages with PHP templates
PHP templates are easy to implement statically, such as installing and using PHP Smarty to make your site static.
2. Generate static pages using PHP file read/write function
PHP generates static page instance code
1. 2. $out 1 = " <title>PHP website Static Tutorial</title>
3.Welcome to the PHP Web Development Tutorial Network www.leapsoul.cn, this article mainly introduces the method of static PHP Web page
4.";
5. $fp = fopen ("leapsoulcn.html", "w");
6. if (! $fp)
7. {
8. Echo "System Error";
9. exit ();
10.}
One. else {
Fwrite ($fp, $out 1);
Fclose ($FP);
echo "Success";
15.}
?>.
3. Generate a static page using the PHP output control function
The output control function, which uses and controls the cache to generate static HTML pages, also uses the PHP file read-write function.
PHP generates static page instance code
1. 2. Ob_start ();
3. Echo "".
4. "".
5. " <title>PHP website Static Tutorial</title>".
6. "".
7. "Welcome to the PHP Web Development Tutorial Network www.leapsoul.cn, this article mainly introduces the method of static PHP Web page".
8. "";
9.
$out 1 = ob_get_contents ();
One. Ob_end_clean ();
$fp = fopen ("leapsoulcn.html", "w");
if (! $fp)
14. {
. echo "System Error";
() exit ();
17.}
. else
19. {
Fwrite ($fp, $out 1);
Fclose ($FP);
echo "Success";
23.}
?>.
We know that using PHP for Web development, the general implementation of the results of direct 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, in order to obtain the contents of the buffer, and then output to the static HTML page file to achieve the site static.
The idea of PHP generating static pages is to first turn on the cache, then output the HTML content (you can also include the HTML content as a file via include), then get the contents of the cache, and then empty the cache and write the cached content to a static HTML paging file through the PHP file read-write function. 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, note that there can be no output before using Ob_start, such as spaces, characters and so on.
2. The Ob_get_contents function is primarily used to get the contents of the cache to be returned as a string, note that this function must be called before the Ob_end_clean function, otherwise it will not get cached content.
3, the Ob_end_clean function is mainly to empty the contents of the cache and close the cache, success will return true, failure will return false
There are many applications for the PHP output control function, which will be expanded in the future.
At this point, the use of PHP to generate static HTML pages to achieve the static site method is finished, according to the actual situation and needs you can choose a different static method.

Excerpted from V_desigen

http://www.bkjia.com/PHPjc/478275.html www.bkjia.com true http://www.bkjia.com/PHPjc/478275.html techarticle in the development of PHP Web site for website promotion and SEO needs, need to site or local static processing, PHP generated static HTML page There are many ways, such as the use of PHP templates, caching ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.