Introduction to the static generation method of PHP website page

Source: Internet
Author: User
Tags exit functions html page include php file php web development php website

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.

  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.

  PHP Pseudo-static Tutorial: a method to implement URL rewriting using Apache mod_rewrite

  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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
?
$out 1 = "
$fp = fopen ("leapsoulcn.html", "w");
if (! $fp)
{
echo "System Error";
Exit ();
}
Else
{
Fwrite ($fp, $out 1);
Fclose ($FP);
echo "Success";
}
?>

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

1
2
3
4
5
6
7
8
9
Ten
One





'
'
style=
'
'

'

/

<?
Ob_start ();

Echo "         "         <title& Gt PHP website static tutorial </title> ".
        "       "<body> Welcome to visit the PHP website Development Tutorial Network www.leapsoul.cn, this article mainly introduces the PHP website 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" ;
}

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 generates static pages by first opening the cache and then outputting the HTML content (you can also include HTML content as a file through include), and then get the contents of the cache. After emptying the cache, the cached content is written to the static HTML paging file through the PHP file read and 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, 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.

  Note : PHP Web Development Tutorials-leapsoul.cn Copyright, reproduced in the form of links to indicate the original source and this statement, thank you.







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.