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

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

WebStorm Mac版
好用的JavaScript開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Dreamweaver Mac版
視覺化網頁開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。