Easily compile PHP static pages

Source: Internet
Author: User

With PHP's strength, more and more friends are paying attention to it. I have seen many users post and ask about PHP static page article systems in various places. I have done such a system before, let's talk about some ideas for your reference. Now let's review some basic concepts.

I. PHP scripts and dynamic pages.

A PHP script is a server-side scripting program that can be mixed with HTML files by embedding methods, classes, function encapsulation, and other forms to process user requests in a template. Regardless of the method, the basic principle is as follows. Requests made by the client, request a page -----> the WEB server introduces the specified script for processing -----> the script is loaded to the server -----> the PHP parser specified by the server parses the script to form an HTML language ----> the parsed HTML statement is returned to the browser as a package. It is not hard to see that after the page is sent to the browser, PHP does not exist and has been converted into HTML statements. The customer requests a dynamic file, in fact there is no real file, it is a PHP parsing to form a corresponding page, and then sent back to the browser. This page processing method is called "dynamic page ".

2. PHP static page.

A static page is a page on the server that contains only HTML, JS, CSS, and other scripts on the client. The processing method is. The client sends a request to a page ----> the WEB server confirms and loads a page ----> the WEB server sends the page back to the browser as a package. From this process, we can compare the dynamic page to see it now. Dynamic Pages must be parsed by the PHP parser of the WEB server. Generally, you need to connect to the database and perform database access operations to form an HTML language information package. Static pages do not need to be parsed, direct sending without connecting to the database can greatly reduce the pressure on the server, improve the server load capability, and greatly provide the page opening speed and the overall website opening speed. However, the disadvantage is that the request cannot be processed dynamically and the file must exist on the server.

3. parsing templates and templates.

The template does not fill in the html file. For example:


  1. <HTML> 
  2. <TITLE>{title}</TITLE> 
  3. <BODY> 
  4. thisisa{file}file'stemplets  
  5. </BODY> 
  6. </HTML> 

PHP static page processing:

  1. Templetest. php
  3. <?Php 
  4. $Title="Webpage tutorial network test template";
  5. $File="Webjxtesttemplet, <br> author: web@webjx.com";
  7. $Fp=Fopen("Temp.html", "r ");
  8. $Content=Fread($ Fp, filesize ("temp.html "));
  9. $Content.=Str_replace("{File}", $ file, $ content );
  10. $Content.=Str_replace("{Title}", $ title, $ content );
  12. Echo $ content;
  13. ?> 

Template parsing process: The result filling (content) obtained after parsing and processing by the PHP script is entered into the processing process of the template. The template class is usually used. Currently, popular template parsing classes include phplib, smarty, fastsmarty, and so on. The principle of template Parsing is usually replaced. Some programmers are also used to putting determination, loop, and other processing into the template file, using parsing class processing. A typical application is the block concept, which is simply a loop processing. The PHP script specifies the number of loops, how to cyclically substitute, and so on, and then the template parsing class specifically implements these operations.

Well, we have compared the advantages and disadvantages of static pages and dynamic pages. Now let's talk about how to use PHP to generate static files.

Generating static pages in PHP does not refer to the dynamic parsing of PHP, but to outputting HTML pages. Instead, PHP is used to create HTML pages. At the same time, because of the non-writability of HTML, if the HTML we create is modified, We need to delete it and generate it again. (You can also modify the regular expression, but I personally think that it is better to delete and regenerate the regular expression, which is not worth the candle .)

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.