代码分离
使用PHP编程的人都会碰到这样一个问题:当PHP代码和HTML代码在一起的时候,看PHP代码很费劲,整个文件也无法用Dreamweaver来编辑,这对于PHP程序员和美工来讲,修改这样的文件就象一个噩梦。
PHP中的模板(Template)技术就是为了解决这个问题而出现的。PHP模板类有很多,比较常见的是 FastTemplate 和 PHPLib, 因为出现得早,在PHP编程界名声很大。PHP程序员不知道这两个类,就象VB程序员不知道MsgBox函数一样,是一件不可思议的事情。
以前我们需要去下载PHP模板类,现在PHP4有了自己的模板类 IntegratedTemplate 和 IntegratedTemplateExtension,功能和PHPLib 差不多。这两个类是子类和父类的关系。一般我们用 IntegratedTemplateExtension 就可以了。让人感到不可思议的是 IntegratedTemplate 不是从 PEAR 类继承过来,无法用到 PEAR 类的 debug 功能。
以下举例子说明它们的用法,假设 IntegratedTemplate 类和 IntegratedTemplateExtension 类分别在 C:\php4\pear\HTML\ITX.php 和 C:\php4\pear\HTML\ITX.php 中。我们写的代码放在C:\TestPHP\PHP4\Welcome.htm 和 C:\TestPHP\HTML\Welcome.php 中。将C:\TestPHP\PHP4 在Web Server 上设成虚拟目录 /testphp 并且给与脚本执行权限,确认C:\TestPHP\HTML\Welcome.htm 无法通过远端浏览器访问。在 php.ini 里面设置 include_path = ".;C:\php4\pear"
例1:
我们在HTML文件中放置变量的标记,用PHP代码设置变量的值,然后将HTML中的标记替换掉,最后输出到客户浏览器。
以下是 Welcome.htm 代码,我们放了三个PHP tag(变量标记)为: {WelcomeTitle}、{UserName}、{WelcomeMessage}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools