Home > Backend Development > PHP Tutorial > Separation of HTML and PHP code using the IntegratedTemplate class in PHP4_PHP Tutorial

Separation of HTML and PHP code using the IntegratedTemplate class in PHP4_PHP Tutorial

WBOY
Release: 2016-07-13 17:25:38
Original
899 people have browsed it


People who use PHP programming will encounter such a problem: when PHP code and HTML code are together, it is very difficult to read the PHP code, and the entire file cannot be edited with Dreamweaver. This is very difficult for PHP programmers and artists. , modifying such a file is a nightmare.
The template (Template) technology in PHP emerged to solve this problem. There are many PHP template classes, the more common ones are FastTemplate and PHPLib. Because they appeared early, they are very famous in the PHP programming world. PHP programmers do not know these two classes, just like VB programmers do not know the MsgBox function, it is an incredible thing.
In the past we needed to download PHP template classes, but now PHP4 has its own template classes IntegratedTemplate and IntegratedTemplateExtension, which have similar functions to PHPLib. These two classes are related to subclasses and parent classes. Generally we can use IntegratedTemplateExtension. What is incredible is that IntegratedTemplate does not inherit from the PEAR class and cannot use the debug function of the PEAR class.
The following examples illustrate their usage, assuming that the IntegratedTemplate class and IntegratedTemplateExtension class are in C:php4pearHTMLITX.php and C:php4pearHTMLITX.php respectively. The code we wrote is placed in C:TestPHPPHP4Welcome.htm and C:TestPHPHHTMLWelcome.php. Set C:TestPHPHPPHP4 to the virtual directory /testphp on the Web Server and grant script execution permission. Make sure that C:TestPHPHHTMLWelcome.htm cannot be accessed through the remote browser. Set include_path = ".;C:php4pear"
in php.ini Example 1:
We place variable tags in the HTML file, set the variable value with PHP code, and then replace the tags in the HTML , and finally output to the client browser.
The following is the Welcome.htm code. We have placed three PHP tags (variable tags): {WelcomeTitle}, {UserName}, {WelcomeMessage}




{WelcomeTitle}





Hello, {UserName}
{WelcomeMessage}


The following is the Welcome.php code
require_once "HTML/ITX.php";
file://The following is the assignment of values
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template