seatop.com.cn

简单的PHP模板加载类

seatop , 2010年1月2日 , 计算机与网络 , 评论(0) , 引用(0) , 阅读(844) , Via 本站原创 | |
<?php
// 模板加载类
class template{
  var  $_debug = "";//调试模式开关
  var  $_themes = "";//模板加载及替换存放

//调试模式控制函数
  function template($debug=false){
    $this->_debug=$debug;             //调试模式默认为否
  }

//获取模板内容函数
    function loadtemplate($themesfiles){
    $this->_themes=$this->getthemes($themesfiles);//自定义函数打开并读取模板函数getthemes()函数获取模板内容
    $this->debug("加载模板文件成功");    
  }

//替换模板中的标签
    function  setlabel($label,$data){
    $this->_themes=str_replace($label,$data,$this->_themes);
    $this->debug("替换模板标签:".$label."为:".$data);    
  }

//加载模板输出
    function  outtemplate(){
    echo $this->_themes;   //加载模板后显示
    $this->debug("模板加载后输出");
  }

//打开并读取模板文件函数
  function  getthemes($themesfiles){
    $contents="";
    if(file_exists($themesfiles)){
      if(function_exists("file_get_contents")){   //检查file_get_contents()函数是否可用
          $contents=file_get_contents($themesfiles);//读取模板内容
      }
      else{
        $file=fopen($themesfiles,"r");//打开模板文件
        if($file){
          while(!feof($file)){   //读取模板内容
            $contents.=fread($file,1024);
          }
        }
        else{
          $this->debug("打开模板文件:".$themesfiles."失败");
        }
      }
    }
    else{
      $this->debug("模板文件:".$themesfiles."不存在");
    }
    return $contents;
  }

//调试信息显示函数
  function debug($debuginfo){
    if($this->_debug==ture){//当调试控制开关为是时显示调试信息
      echo $debuginfo."<br/>";
    }
  }
}
?>

本文地址:http://www.seatop.com.cn/post/397/

相关日志
[PHP开源程序]html单页面内容发布系统
让mail()支持中文的简单类
PHP中删除文件夹和计算文件夹大小
学习php抓取网页中的图片链接

最后编辑: seatop 编辑于2010/01/02 21:20
Tags: , , ,
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]    点击进入授权页面

 
谷歌搜索
赞助商广告
最新日志
赞助商广告
热门Tags
赞助商广告
最新帖子
赞助商广告