网页模版生成类
/*
网页模版生成类
用途:主要用于静态资源面页的生成..本类也适用于其它系统的静态页面的生成
调用实例:
$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);
}
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools