Use PHP to achieve static WEB pages

Source: Internet
Author: User

In recent years, the World Wide Web (also known as the World Wide Information Network (WWW) has continuously changed the face of information processing technologies. WEB has quickly become an effective medium for people to communicate and collaborate with businesses. Almost all information technology fields are affected by the WEB. Web access brings more users and more data, which means more pressure on servers and databases and slow response speed for end users. Compared with increasing CPU, disk drive, and memory to keep up with this demand, static WEB pages should be a more practical and economical choice.

Use PHP to implement static WEB pages, as shown in function gen_static_file ().

Function gen_static_file ($ program, $ filename)
{
$ Program 1 = "/usr/local/apache/htdocs/php/". $ program;
$ Filename1 = "/usr/local/apache/htdocs/static_html/". $ filename;
$ Pai_str = "/usr/local/php4/bin/php". $ program1. "}". $ filename1 ."";
System ($ response _str );
Echo $ filename. "generated. <br> 〉";
}

This function is the key to static, that is, the PHP dynamic page program is not sent to the browser, but is input to the file named $ filename (2 ). Among the two parameters, $ program is a PHP dynamic page program, and $ filename is the name of the generated Static Page (you can customize naming rules as needed. This is important, see the following description ), /usr/local/php4/bin/php is a part of PHP that provides the function of inputting program files. System is a function used to execute External commands in PHP. We can also see that all php programs that generate dynamic pages should be placed in the/php/directory, all newly generated static pages will appear in the/static_html/directory (these paths can be set as needed ).

Let's take a specific example to see how the static page of college_static.php is generated.

Function gen_college_static ()
{
For ($ I = 0; $ I <=32; $ I ++> 〉
{
Putenv ("province_id =". $ I); // * use the PHP file to retrieve data from the database.
$ Filename = "college_static". $ I. ". html ";
Gen_static_file ("college_static.php", $ filename );
}

From this function, we can see that by calling the function gen_static_file (), college_static.php goes through the static state and becomes the 33 page college.static0.html ~ College.static33.html, where $ filename changes with $ I. Of course, you can also take values directly from the database to control the number and name of generated static pages. Other programs should call the generated static pages in the same way as the static page naming rules.

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.