PHP static page

Source: Internet
Author: User
Author: Matrix @ Two_Max Source: http://www.otm.cn saw a lot of friends in various places Post asked PHP natural static article system method, previously had such a system, then talk about some insights, for your reference. Well, let's look back at some of the basic author: Matrix @ Two_Max Source: http://www.otm.cn

I have seen many of my friends post on various locations and ask about PHP's native static article system method. I have done this kind of system before, so I will talk about some insights for your reference. Well, let's look back at some basic concepts.

I. PHP scripts and dynamic pages.

PHP script is a server-side script program. it can be mixed with HTML files through embedded methods, classes, function encapsulation, and other forms. it is used as a template to process user requests. The basic principle of this method is as follows. Client requests, beg for a page -----> The WEB server imports the specified script for processing -----> The script is loaded into the server -----> the PHP parser specified by the server parses the script to form an HTML language situation ----> the parsed HTML statement is returned to the browser as a package. As a result, PHP does not exist after the page is sent to the browser and has been converted to HTML statements. The customer begged to be a dynamic file. In fact, there is no real file in it. it is a page parsed by PHP and sent back to the browser. This page processing method is called "dynamic page ".

2. static pages.

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 makes a request to request a page ----> The WEB server confirms and loads the page ----> The WEB server transfers the page back to the browser as a package. From this process, let's take a look at the dynamic page. Dynamic pages must be parsed by the PHP parser of the WEB server. Generally, you need to connect to the database for database access control and then generate 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, increase the server load, and greatly provide the page opening speed and the overall website opening speed. However, the problem 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:

Temp.html


{Title}

This is a {file} file's templets



PHP processing:

Templetest. php

$ Title = 'webpage tutorial network test template ';
$ File = 'webjx test templet,
Author: web@webjx.com ';

$ Fp = fopen ('temp.html ', 'r ');
$ Content = fread ($ fp, filesize ('temp.html '));
$ Content. = str_replace ('{file}', $ file, $ content );
$ Content. = str_replace ('{title}', $ title, $ content );

Echo $ content;
?>
 


The template parsing process is the processing process of filling the results obtained after parsing and processing by PHP scripts into 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 interchange. Some programmers are also used to putting determination, loop, and other processing into the template file, using parsing class processing, and using the block concept as a model. In short, it is a loop processing. The PHP script specifies the number of loops and how to generate loops, and then the template parsing class implements these controls.

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.