PEAR里的HTML_Template_IT是一个简单而且容易使用的类。 ********** 建立一个模板文件 **************** “符号”命名规则 为下面的正则表达式: {[0-9A-Za-z_-]+} ”块“ 格式为下面的,块名的命名规则和“符号”一样的: ... 块内容 ... 块允许嵌套,你必须首先设置并分析最内层的块,然后再设置和分析上一层的块。 *********** 主要方法 *********** 构造函数: void IntegratedTemplate::IntegratedTemplate ([string $root = ""]) $root = 摸板根目录 你也可以用 void IntegratedTemplate::setRoot (string $root) 方法设置模板目录;该方法不能被静态调用。 --------------------------------------------------------- 加载模板: boolean IntegratedTemplate::loadTemplatefile (string $filename, boolean [$removeUnknownVariables = TRUE], boolean [$removeEmptyBlocks = TRUE]) $filename = 模板文件名 $removeUnknownVariables = 设置是否移除未知的变量 $removeEmptyBlocks = 设置是否移除空块 成功返回TRUE,失败返回FALSE。 该方法不能被静态调用 ------------------------------------------------------- 指定当前要处理的块: boolean IntegratedTemplate::setCurrentBlock ([string $block = "__global"]) $block = 块名 成功返回TRUE,失败会返回一个PEAR_Error对象,里面包含错误 描述。该方法不能被静态调用。 ------------------------------------------------------- 用变量替换当前要处理的块里的“符号”: void IntegratedTemplate::setVariable (mixed $placeholder [, mixed $variable = ""]) $placeholder = 要替换的符号名,如果$variable是一个数组, 那就用符号名作为这个数组的索引并用这个索 引的数组元素的数据替换符号 $variable = 变量名或数组名 该函数不能被静态调用 -------------------------------------------------------- 分析当前正处理的块: void IntegratedTemplate::parseCurrentBlock () 失败会返回一个PEAR_Error对象,里面包含错误 描述。该方法不能被静态调用。 --------------------------------------------------------- 处理完成输出: void IntegratedTemplate::show ([string $block]) $block = 要返回的块 如果没设置$block,将返回完整的模板 ******************* 简单示例(示例来自PEAR的在线手册)***** Usage Example Example 25-1. main.tpl.htm模板文件,在"./templates"目录下 {DATA} Example 25-2. PHP脚本 array("Stig", "Bakken"), "1" => array("Martin", "Jansen"), "2" => array("Alexander", "Merz") ); $tpl = new HTML_Template_IT("./templates"); $tpl->loadTemplatefile("main.tpl.htm", true, true); foreach($data as $name) { foreach($name as $cell) { // Assign data to the inner block $tpl->setCurrentBlock("cell") ; $tpl->setVariable("DATA", $cell) ; $tpl->parseCurrentBlock("cell") ; } // Assign data and the inner block to the // outer block $tpl->setCurrentBlock("row") ; $tpl->parseCurrentBlock("row") ; } // 输出 $tpl->show(); ?> Example 25-3. 输出 Stig Bakken Martin Jansen Alexander Merz ******************************************************* HTML_Template_IT里面还有一个ITX类,可以完成更加复杂的功能, 继承自IT类;ITX。PHP文件的原代码里包含了这个类的方法说明。 关于HTML_Template_IT其他方法的详细说明请参见PEAR的手册,地址为 http://pear.php.net/manual/en/package.html.html-template-it.php --希望大家能好好利用PEAR这个库写出更多更好的PHP程序!--

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment