PHP static page generation method _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP static page generation method. In PHP website development, full-site or partial static processing is required for website promotion and SEO. PHP provides multiple methods to generate static HTML pages, for example, if PHP templates and caches are used in PHP website development for website promotion and SEO needs, the website must be completely or partially statically processed. there are multiple ways for PHP to generate static HTML pages, for example, to use PHP templates and cache to achieve static pages, we will discuss how PHP generates static pages in the form of PHP instance tutorials today. There are two static page methods: pseudo-static, url rewriting, and static. The following describes the static page method in PHP.
What is PHP static
A simple understanding of PHP static is to make website pages displayed in the form of static HTML in front of visitors. PHP static is divided into pure static and pseudo static, the difference between the two is that the processing mechanism for generating static pages in PHP is different.
PHP static HTML page generation method
1. use PHP templates to generate static pages
It is very convenient to implement static PHP templates, such as installing and using PHP Smarty to implement static websites.
2. use the php file read/write function to generate a static page
PHP generates static page instance code
1. 2. $ out1 =" PHP static website tutorial
3.Welcome to www.leapsoul.cn for PHP website development. This article mainly introduces the static PHP website page method.
4.";
5. $ fp = fopen ("leapsoulcn.html", "w ");
6. if (! $ Fp)
7 .{
8. echo "System Error ";
9. exit ();
10 .}
11. else {
12. fwrite ($ fp, $ out1 );
13. fclose ($ fp );
14. echo "Success ";
15 .}
16.?>
3. use the Output Control function of PHP to generate a static page.
The Output Control function uses and controls the cache to generate static HTML pages. It also uses the php file read/write function.
PHP generates static page instance code
1. 2. ob_start ();
3. echo"".
4 ."".
5 ." PHP static website tutorial".
6 ."".
7 ."Welcome to www.leapsoul.cn for PHP website development. This article mainly introduces the static PHP website page method.".
8 ."";
9.
10. $ out1 = ob_get_contents ();
11. ob_end_clean ();
12. $ fp = fopen ("leapsoulcn.html", "w ");
13. if (! $ Fp)
14 .{
15. echo "System Error ";
16. exit ();
17 .}
18. else
19 .{
20. fwrite ($ fp, $ out1 );
21. fclose ($ fp );
22. echo "Success ";
23 .}
24.?>
We know that PHP is used for website development. Generally, the execution results are directly output to the browser. to generate a static page using PHP, you need to use the output control function to control the cache to obtain the content in the cache, and then output to the static HTML page file to achieve static website.
The idea of generating static pages in PHP is: first enable caching, then output HTML content (you can also include HTML content in the form of a file through include), and then get the content in the cache, after the cache is cleared, the PHP file read/write function writes the cached content to the static HTML page file. Php file read/write tutorial?
The process of obtaining the output cache content to generate a static HTML page requires three functions: ob_start (), ob_get_contents (), and ob_end_clean ().
Knowledge Point:
1. the ob_start function is generally used to enable caching. Note that no output, such as spaces or characters, is allowed before the ob_start function is used.
2. the ob_get_contents function is mainly used to obtain the cached content and return it as a string. Note that this function must be called before the ob_end_clean function; otherwise, the cached content cannot be obtained.
3. the ob_end_clean function clears the content in the cache and closes the cache. if the cache is successful, True is returned. if the cache fails, False is returned.
The Output Control function of PHP has many applications and will be available in the future.
At this point, the method for generating static HTML pages using PHP to achieve static website is described. you can choose different static methods based on the actual situation and requirements.

From v_desigen

...

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.