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

PHP
discuz安全提问算法
PHP静态新闻列表自动生成代码
用PHP实现图象锐化代码
PHP生成月历代码
用PHP实现的随机广告显示代码
用PHP实现维护文件代码
关于在php.ini中添加extension=php_mysqli.dll指令的说明
PHP 中的批处理的实现
木翼下载系统中说明的PHP安全配置方法
php为什么选mysql作为数据库? Mysql 创建用户方法
PHP如何编写易读的代码
PHP 优化配置——加速你的VBB,phpwind,Discuz,IPB,MolyX
php下一个阿拉伯数字转中文数字的函数
Discuz5.5.0代码高亮显示+运行代码框合成插件 下载
PHP+FLASH实现上传文件进度条相关文件 下载
发布一个迷你php+AJAX聊天程序[聊天室]提供下载
在普通HTTP上安全地传输密码
php中ob(Output Buffer 输出缓冲)函数使用方法
php 用sock技术发送邮件的函数
真正的ZIP文件操作类(php)

网友原创的PHP模板类代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 134 ::
收藏到网摘: 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();