网友原创的PHP模板类代码
2008-09-07 00:00
204 查看
<?php class Lightpage_Template { var $Tpl_Header; var $Tpl_Footer; var $Tpl_Parsing; var $Tpl_Template; var $Tpl_Dirname; var $Tpl_Parse_String; var $Tpl_Parse_Array; var $Tpl_Result; function __construct() { $this->Tpl_Header = NULL; $this->Tpl_Footer = NULL; $this->Tpl_Parsing = array(); $this->Tpl_Template = 'list.html'; $this->Tpl_ToParse = NULL; $this->Tpl_Parse_String = array(); $this->Tpl_Parse_Array = array(); $this->Tpl_Result = NULL; return true; } function Parse_Template() { $this->Tpl_Parse_String = array(); $this->Tpl_Parse_Array = array(); if($this->Tpl_Header!=NULL) { array_push($this->Tpl_Parse_String,$this->Tpl_Header);array_push($this->Tpl_Parse_Array,'{header}'); } if($this->Tpl_Footer!=NULL) { array_push($this->Tpl_Parse_String,$this->Tpl_Footer);array_push($this->Tpl_Parse_Array,'{footer}'); } if(count($this->Tpl_Parsing)!=1) { foreach($this->Tpl_Parsing as $Tpl_Key => $Tpl_Value) { array_push($this->Tpl_Parse_String,$Tpl_Value); array_push($this->Tpl_Parse_Array,'{'.$Tpl_Key.'}'); } } if($this->Tpl_Template!=NULL && $this->Tpl_ToParse==NULL) { $this->Tpl_ToParse = file_get_contents(root.'./Templates/'.$this->Tpl_Template); } $this->Tpl_Result = str_replace($this->Tpl_Parse_Array,$this->Tpl_Parse_String,$this->Tpl_ToParse); return $this->Tpl_Result; } } ?>
php模板用法:
$Mdl = new Lightpage_Template(); $Mdl->Tpl_Header = 'zzz'; $Mdl->Tpl_Footer = ''; $Mdl->Tpl_Parsing = ''; $Mdl->Tpl_Template = 'list.html'; echo $Mdl->Parse_Template();
相关文章推荐
- 网友原创的PHP模板类代码
- 效率较高的php下读取文本文件的代码[原创]_php技巧_脚本之家
- [PHP]图片上传代码【原创】
- PHP上传Excel文件导入数据到MySQL数据库(详细示例代码)【原创】
- php简单隔行变色功能实现代码 原创
- 百度Ping服务,向百度推送你的博客文章,加速收录保护原创,附PHP代码
- PHP正则删除html代码中a标签并保留标签内容的方法[原创]_php技巧_脚本之家
- php简单隔行变色功能实现代码[原创]_php技巧_脚本之家
- 【原创】真正的驱动入门(—)[附小程序代码]作 者:CCDeath时 间:2007-12-07,23:13链 接:http://bbs.pediy.com/showthread.php?t=56192【文章标题】: 真正的驱动入门(—)[附小程序代码]【文
- 效率较高的php下读取文本文件的代码 原创
- php读取txt文件组成SQL并插入数据库的代码(原创自Zjmainstay)
- 用PHP写一段代码,实现不使用第3个变量,交换$a、$b的值,$a、$b的初始值自己定。(五种方法实现)
- 2款PHP无限级分类实例代码
- 40条优化php代码的小实例
- 分享10段PHP常用代码
- php实现有序数组打印或排序的方法【附Python、C及Go语言实现代码】
- mysql分库时PHP选择连接数据库的代码
- 代码练习之 登陆 PHP会话控制 session cookie