当前位置: 首页 > 图文教程 > 网络编程 > PHP > 网友原创的PHP模板类代码

PHP
一个自定义位数的php多用户计数器代码
php实现的MySQL通用查询程序
一个简单的php实现的MySQL数据浏览器
php桌面中心(一) 创建数据库
php桌面中心(二) 数据库写入
php桌面中心(三) 修改数据库
php桌面中心(四) 数据显示
织梦模板标记简介
DedeCms模板安装/制作概述
PHP中的CMS的涵义
手把手教你使用DedeCms的采集的图文教程
利用PHP和AJAX创建RSS聚合器的代码
mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
Linux下进行MYSQL编程时插入中文乱码的解决方案
推荐Discuz!5的PHP代码高亮显示与实现可运行代码
不错的一篇面向对象的PHP开发模式(简写版)
用PHP实现多服务器共享SESSION数据的方法
用header 发送cookie的php代码
PHP的开发框架的现状和展望
使用 eAccelerator加速PHP代码的目的

网友原创的PHP模板类代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 128 ::
收藏到网摘: n/a

学习php模板的朋友,可以参考下

复制代码 代码如下:

<?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();