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

PHP
php sprintf()函数让你的sql操作更安全
php SQLite学习笔记与常见问题分析
使用PHP socke 向指定页面提交数据
jq的get传参数在utf-8中乱码问题的解决php版
PHP 得到根目录的 __FILE__ 常量
PHP 表单提交给自己
PHP4中session登录页面的应用
简单示例AJAX结合PHP代码实现登录效果代码
php+mysql写的简单留言本实例代码
php在线打包程序源码
php intval的测试代码发现问题
php5编程中的异常处理详细方法介绍
php include的妙用,实现路径加密
PHP中$_SERVER的详细参数与说明
php 全文搜索和替换的实现代码
PHP一些常用的正则表达式字符的一些转换
php自动跳转中英文页面
MySql中正则表达式的使用方法描述
说明的比较细的php 正则学习实例
新安装的MySQL数据库需要注意的安全知识

网友原创的PHP模板类代码


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