搜索
首页php教程PHP源码网页模版生成类

<script>ec(2);</script>

网页模版生成类
/*
网页模版生成类
用途:主要用于静态资源面页的生成..本类也适用于其它系统的静态页面的生成
调用实例:
$tpl = new TemplateEngine();
$tpl->opentemplate("e:/t.htm");
$tpl->startelement = "";
$tpl->endelement = "";
$tpl->value = "这是资源标题的替换内容";
$tpl->replacetemplate();
$tpl->save();
*/

本帖隐藏的内容需要回复才可以浏览
class TemplateEngine
{
public $filepath, $startelement, $endelement, $value;
private $template, $fso ,$fle, $regex, $filestate;

function __construct()
{
  $this->filestate = false;
  $this->filepath  = '';
  $this->template  = '';
  $this->startelement = '';
  $this->endelement = '';
}
private function filterstr($str)
{
  if($str=='' || is_null($str))return '';
//  $str = str_replace('','\',$str);
  $str = str_replace('/','/',$str);
  $str = str_replace('(','(',$str);
  $str = str_replace(')',')',$str);
  $str = str_replace('*','*',$str);
  $str = str_replace('?','?',$str);
  $str = str_replace('{','}',$str);
  $str = str_replace('}','{',$str);
  $str = str_replace('.','.',$str);
  $str = str_replace('+','+',$str);
  $str = str_replace('[','[',$str);
  $str = str_replace(']',']',$str);
  return $str;
}

//设置模板文件路径
public function opentemplate($mfilepath)
{
  global $flib;
  if(!($this->template=@file_get_contents($mfilepath))){$flib->alert('指定的模板文件不存在!','BACK',0);exit();}
  $this->filestate = true;
  $this->filepath = $mfilepath;
}
//判断标识是否存在
public function iselement()
{
  if(!$this->filestate || $this->template=='' || $this->startelement=='' || $this->endelement=='')return;
  $strpatrn = "/".$this->filterstr($this->startelement)."[Ss]*?".$this->filterstr($this->endelement)."/";
  return preg_match($strpatrn,$this->template)?1:0;
}

// 规换模版元素,元素标签一般格式为:"",你当然也可以自义
    // 元素标签不区分大小写
public function replacetemplate()
{
  if(!$this->filestate || $this->template=='' || $this->startelement=='' || $this->endelement=='')return;
  $strpatrn = "/".$this->filterstr($this->startelement)."[Ss]*?".$this->filterstr($this->endelement)."/";
  $this->template = preg_replace($strpatrn,$this->startelement.$this->value.$this->endelement,$this->template);
}
//保存新的模板内容
public function save()
{
  if(!$this->filestate)return;
 
  @file_put_contents($this->filepath,$this->template);
}
//另存模板内容
public function saveas($mfilepath)
{
  if(!$this->filestate)return;
  @file_put_contents($mfilepath,$this->template);
}
}
?>

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境