网友原创的PHP模板类代码

所属分类: 网络编程 / PHP编程 阅读数: 936
收藏 0 赞 0 分享

复制代码 代码如下:

<?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 setTime 设置当前时间的代码

在用JAVA中有个 Calendar 可设置当前时间,在PHP中找了半天,终于给我找到了这个函数,嘎嘎
收藏 0 赞 0 分享

PHP 图片水印类代码

这个类功能很强大,细节很棒!希望大家喜欢,并积极指点
收藏 0 赞 0 分享

PHP实现手机归属地查询API接口实现代码

主要使用curl实现,需要开启php对curl的支持
收藏 0 赞 0 分享

php 解决旧系统 查出所有数据分页的类

不同之处在于 没有实现分页的系统, 默认全部查出来 现在就要不能动后台的基础上进行操作 可以采用 相应的 如下 代码
收藏 0 赞 0 分享

PHP的简易冒泡法代码分享

基础的东西,感觉代码还不够简洁,希望高手指导修改,脚本之家特为大家多准备了几个,方便测试学习
收藏 0 赞 0 分享

PHP 利用AJAX获取网页并输出的实现代码(Zjmainstay)

PHP 利用AJAX获取网页并输出的实现代码,需要的朋友可以参考下
收藏 0 赞 0 分享

php数组一对一替换实现代码

以下方法能实现匹配关键词并分别对关键词做特殊处理的功能,需要的朋友可以参考下
收藏 0 赞 0 分享

关于UEditor编辑器远程图片上传失败的解决办法

因为单纯喜欢 UEditor 的界面,于是把项目中原先的编辑器进行的替换,但在后续操作中发现一些问题,就是远程图片上传
收藏 0 赞 0 分享

Windows下部署Apache+PHP+MySQL运行环境实战

本来嘛,部署PHP没什么复杂,找各种版本着实头疼了一下。
收藏 0 赞 0 分享

比较discuz和ecshop的截取字符串函数php版

网上看到一篇文章 discuz和ecshop截取字符串的两个函数,比较了一下两个版本的函数,都各有局限,只能在特定的前提下使用,但是学习一下有利于拓宽思路,了解PHP的扩展功能
收藏 0 赞 0 分享
查看更多