Introduction to the method of generating static PHP Web pages _php Tutorial

Source: Internet
Author: User
Tags php web development php website vars
page Staticmethod, is divided into two kinds, one is pseudo-static, is URL rewrite, one is you really static. Described below PHPstatic method in the page.

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.

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. $out 1 = "PHP website Static Tutorial
  2. Welcome to the PHP Web Development Tutorial Network www.leapsoul.cn, this article mainly introduces the method of static PHP Web page
  3. ";
  4. $fp = fopen("leapsoulcn.html","W");
  5. if (! $fp )
  6. {
  7. Echo "System Error";
  8. Exit ();
  9. }
  10. Else {
  11. fwrite ($fp,$out 1);
  12. fclose ($fp);
  13. Echo "Success";
  14. }
  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. Ob_start ();
  2. Echo "".
  3. "" .
  4. "PHP website Static Tutorial".
  5. "" .
  6. "Welcome to the PHP Web Development Tutorial Network www.leapsoul.cn, this article mainly introduces the PHP Web page static method" .
  7. "" ;
  8. $out 1 = Ob_get_contents ();
  9. Ob_end_clean ();
  10. $fp = fopen ("leapsoulcn.html","W");
  11. if (! $fp )
  12. {
  13. Echo "System Error";
  14. Exit ();
  15. }
  16. Else
  17. {
  18. fwrite ($fp,$out 1);
  19. fclose ($fp);
  20. Echo "Success";
  21. }
  22. ?>

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.

Original address: http://www.leapsoul.cn/?p=986


http://www.bkjia.com/PHPjc/445791.html www.bkjia.com true http://www.bkjia.com/PHPjc/445791.html techarticle 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. In the development of PHP website ...

  • 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.