Home > php教程 > php手册 > PHP快速模板技术

PHP快速模板技术

WBOY
Release: 2016-06-21 09:15:15
Original
1173 people have browsed it

模板

//此页是直接显示
//处理好变量的值
$title="这是标题";
$author="这是作者";
$content="这是内容";
$times=date("Y年m月d日");
 //调入模板程序模块
include("template.inc");
//创建一个模板实例mytemp
$mytemp = new Template("."); //此处.为模板文件当前目录,若模板文件在template目录中就填入template
//设置MyFileHandle文件句柄指向我们所要调用的模板文件template.html
$mytemp->set_file("MyFileHandle","template.html");
//调用模板的set_var方法,设置模板中的变量title值为$title,author为$author等
$mytemp->set_var("title", $title);
$mytemp->set_var("author", $author);
$mytemp->set_var("times", $times);
$mytemp->set_var("content", $content);
//调用模板的parse方法,对MyFileHandle文件句柄所指向的模板文件进行分析,替换其中相应变量
//并把替换结果即完整的HTML文件内容保存在字串变量MyOutput中
$mytemp->parse("MyOutput","MyFileHandle");
// 打印输出结果字串变量MyOutput的值 ,直接输出
$mytemp->p("MyOutput");
?>



Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template