How do I generate a static page using the PHP language?

Source: Internet
Author: User
Tags php language php example php web development

In the PHP network development and search engine optimization site promotion and other aspects of the needs of the space station site or local static processing, PHP generated static HTML page There are many ways, such as the use of PHP templates, caching static pages to implement, today to the PHP instance tutorial Discusses how to form a static page of PHP generation. Static page methods, divided into two types, one is pseudo-static, that is, url rewrite, one is your real static. Here, the small part explains the PHP static page method.



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 learning >>
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

$out 1 = "
Welcome to the PHP Web site development Tutorial Network, this article mainly introduces the PHP Web page static method
";
$fp = fopen ("leapsoulcn.html", "w");
if (! $fp)
{
echo "System Error";
Exit ();
}
else {
Fwrite ($fp, $out 1);
Fclose ($FP);
echo "Success";
}
?>

3.PHP Example Tutorial -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

Ob_start ();
echo "".
"".
"".
"".
"Welcome to the PHP Web Development Tutorial Network, this article mainly introduces the PHP Web page static method."
"";
$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 Web Development 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.

The above examples of PHP tutorial For example, using PHP to generate static HTML pages to achieve a static Web site method will be used in the work, I hope that the scholars under the line more practice. Depending on the actual situation and needs, you can choose a different static method. For more tutorials on PHP videos , you are welcome to learn to watch online! Www.kokojia.com


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