Easily write php static pages _php Tutorial

Source: Internet
Author: User
With the strong PHP, attention to its friends are more and more, I see a lot of friends in various places to ask PHP static page article system method, has done before such a system, then talk about some views, for your reference. Well, let's go back to some basic concepts.

One, PHP script with dynamic page.

PHP script is a server-side script, can be embedded and other methods and HTML files can be mixed, or class, function encapsulation and other forms, in the form of templates to the user request processing. In any way, the rationale for it is such. Requested by the client, request a page-----The >web server introduces the specified script for processing-----> script is loaded into the server-----> parsing the script by the server-specified PHP parser forms the HTML language----> The parsed HTML statement is passed back to the browser in a package way. It is not difficult to see that after the page is sent to the browser, PHP does not exist, has been converted into an HTML statement. Customer requests for a dynamic file, in fact there is no real file exists there, is the PHP parsing the corresponding page, and then sent back to the browser. This kind of page processing is called "Dynamic page".

Second, PHP static page.

A static page is a page that does exist on the server side that contains only HTML and client-run scripts such as JS,CSS. The way it's handled is. A request is made by a client requesting a page----the >web server confirms and loads a page----The >web server passes the page back to the browser as a package. From this process, we compare the dynamic page, you can now. The dynamic page needs to be parsed by the PHP parser of the Web server, and it is usually necessary to connect the database, make the database access operation, then the HTML language information packet can be formed, while the static page, no need to parse, need not connect the database, send directly, can greatly reduce the server pressure, improve the server load capacity, Dramatically provides page opening speed and website overall opening speed. However, the disadvantage is that the request cannot be processed dynamically and the file must exist on the server.

Three, template and template parsing.

The template is not yet populated with the content HTML file. For example:

Temp.html

 
 
  1. <HTML>
  2. < TITLE > {title} TITLE>
  3. <BODY>
  4. Thisisa{file}file ' Stemplets
  5. BODY>
  6. HTML>

PHP static page Processing:

 
 
  1. templetest.php
  2. php
  3. $ title = "Web Teaching Network test template" ;
  4. $ file = "Webjxtesttemplet,
    Author:web@webjx.com ";
  5. $ FP = fopen ("temp.html", "R");
  6. $ content = fread ($FP, FileSize ("temp.html"));
  7. $ content. = Str_replace ("{file}", $file, $content);
  8. $ content. = Str_replace ("{title}", $title, $content);
  9. Echo$content;
  10. ?>

Template parsing processing, will be after the PHP script parsing processing results of filling (content) into the template processing process. Usually with the help of a template class. At present, the more popular template parsing class has phplib,smarty,fastsmarty and so on. The principle of template parsing processing is usually a replacement. Some programmers are accustomed to deciding, looping and other processing into the template file, with the Analytic class processing, the typical application for the block concept, simply to be a loop processing. The PHP script specifies the number of cycles, how to iterate, and so on, which is implemented by the template parsing class.

Well, compared to the static page and dynamic page each of the pros and cons, now we say, how to generate static files in PHP.

PHP generated static page does not refer to the dynamic parsing of PHP, the output of HTML pages, but the use of PHP to create HTML pages. At the same time, because the HTML is not writable, we create the HTML if there are changes, we need to delete the regeneration. (Of course, you can also choose to use the regular to modify, but personally think that does not make it easier to delete the regeneration is faster, some outweigh the loss.) )


http://www.bkjia.com/PHPjc/446486.html www.bkjia.com true http://www.bkjia.com/PHPjc/446486.html techarticle with the strong PHP, attention to its friends are more and more, I see a lot of friends in various places to ask PHP static page article system method, has done such a system before, then talk about ...

  • Related Article

    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.