Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754315
  • 博文数量: 787
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5015
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-22 15:17
文章分类

全部博文(787)

文章存档

2008年(787)

我的朋友

分类:

2008-09-25 16:10:21

PHP快速模板技术[@more@]//此页是直接显示处理好变量的值
$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");
?>

--------------------next---------------------

阅读(678) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~