PHP-Web exploitation program development: Application Template

Source: Internet
Author: User
Every developer who has performed large-scale PHP-Web application design has the following experiences: spending a large amount of time writing Hypertext statements, page formatting, and art; or when the integrated program code spends a large amount of money on HTML static pages

Every developer who has performed large-scale PHP-Web application design has the following experiences: spending a large amount of time writing Hypertext statements, page formatting, and art; or it takes a lot of time for the integrated program code to work with HTML static pages. Indeed, the Web development using scripting language does not easily remove data processing and data display. However, when many people work together, if data and display cannot be removed, the development efficiency will be greatly affected, and the division of professional work will be carried out. In order to determine the title, PHP also provides its own solution plan, there are a variety of, this article is important to first introduce the Template class in PHPLIB.

I. template processing design
Template processing:

  • Read the HTML code used for display from the template file.
  • Combine the template file with the actual natural data to generate the results.
  • Promise to process multiple templates at the same time.
  • Promise template nesting.
  • Promise to process a separate part of the template.



The template class is designed to read the HTML code displayed from multiple template files, place the dynamic data in the display code into the data obtained by The PHP program operation, and then output the data in a certain order. The swap part can be set freely.

The HTML code used to read the Display adopts the file reading method.
Template files and data are exchanged using regular expressions.
Processing multiple templates is implemented using array storage.
An important idea for implementing template nesting is to treat the template and the output (any intermediate analysis results) equally and can be used for interchange.
The individual parts are processed by setting tags in the template file, and then holding the tags in the regular expression exchange to achieve partial replacement.

II. implementation of the template processing class
See Template. inc in PHPLib for a total of 345 lines of code with specific comments. The following lists some important functions for your reference:
1) function set_file ($ handle, $ filename = "") line 77, read the file
2) function set_var ($ varname, $ value = '') line 119, set ING data-change variables
3) function set_block ($ parent, $ handle, $ name = '') line 96, set annotation
4) function subst ($ handle) line 136 performs data exchange
5) function parse ($ target, $ handle, $ append = false) line 165: implements the combination of template files and data.
6) function p ($ varname) line 268, output processing results
Note: I downloaded the php-lib7.2c of the Template. inc file in line 95th less "/", plus after the application is normal.

III. template processing applications
3.1 Basic example
For the sake of simplicity, it is assumed that the template file, the PHP file of the application template, and the file of the template processing class are all placed in the same directory. The habit in PHPLIB is to apply the ihtml suffix to the template file suffix.
The following is the template file to be applied:



Test the application Template

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.