方便实用的PHP生成静态页面类(非smarty)

前端之家收集整理的这篇文章主要介绍了方便实用的PHP生成静态页面类(非smarty)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="73598" class="copybut" id="copybut73598" onclick="doCopy('code73598')"> 代码如下:

<div class="codebody" id="code73598">
//
/
/
/
Version : 5.2.5 /
/
Author : liqiangwork#sohu.com /
/
QQ : 570937581 /
/
/
/
/
//-----------------------------生成静态的类-------------------------------
class Makehtml{
public $MbUrl,$OutUrl,$AllHtml,$SouChar,$ObjChar; //变量
public $row; //游标
public $Shuzusou,$Shuzuobj; //替换的字符串数组
//-----------------------初始化-------------------------
function __construct(){ //初始化
$this->MbUrl="";
$this->OutUrl="";
$this->AllHtml="";
$this->sql="";
$this->SouChar="";
$this->ObjChar="";
}
//-----------------------------自动按字段替换---------------------------
function AutoReplace(){
//------------------自动获取要替换的字符串-------------------
$tlen=count($row);
$shuzu1=array();
$shuzu2=array();
if($row){
$i=0;
foreach($row as $key => $value){
$shuzu2[i]="<=\$".$key."\$>";
$shuzu1[i]=$value;
$i++;
}
$this->Replacehtml(shuzu2,shuzu1);
}
//------------------自动获取要替换的字符串-------------------
}
//-----------------------------自动按字段替换完成------------------------
//-----------------------------批量替换数组--------------------------
function Replacehtml($Shuzusou,$Shuzuobj){ //批量替换数组
if(count($Shuzusou)!=count($Shuzuobj)){
exit("替换数组不匹配");
}
if($this->AllHtml==""){
exit("没有要替换的内容");
}
for($i=0;$i<count($Shuzusou);$i++){
$this->AllHtml=str_replace($Shuzusou[$i],$Shuzuobj[$i],$this->AllHtml);
//print("
".$Shuzusou(i)."=".$Shuzuobj(i)."
")
}
}
//-----------------------------批量替换数组完成--------------------------
//-----------------------------读取文件---------------------------------
function Readfile(){
$file=fopen($this->MbUrl,"r");
$fsize=filesize($this->MbUrl);
$this->AllHtml=fread($file,$fsize);
fclose($file);
}
//-----------------------------读取文件完成------------------------------
//-----------------------------保存文件---------------------------------
function SaveFile(){
$file=fopen($this->OutUrl,"w");
fwrite($file,$this->AllHtml);
fclose($file);
}
//-----------------------------保存文件完成------------------------------
}
//------------------------------生成静态的类完成-------------------------------

相关实例: <div class="codetitle"><a style="CURSOR: pointer" data="65312" class="copybut" id="copybut65312" onclick="doCopy('code65312')"> 代码如下:
<div class="codebody" id="code65312">
//------------------静态生成----
$MyMake=new Makehtml;
$MyMake->MbUrl="News_Show.shtml";
$MyMake->Readfile();
$THTml=$MyMake->AllHtml;
$shuzu1=array();
$shuzu2=array();
$shuzu1[0]="<=\$keybord\$>";
$shuzu1[1]="<=\$description\$>";
$shuzu1[2]="<=\$title\$>";
$shuzu1[3]="<=\$Title1\$>";
$shuzu1[4]="<\$=Bid\$>";
$shuzu1[5]="<\$=Id\$>";
$shuzu1[6]="<=\$Contentb\$>";
$shuzu1[7]="<\$=BigId\$>";
$shuzu1[8]="<=\$Date\$>";
$shuzu1[9]="<=\$City\$>";
$shuzu1[10]="<=\$SmallId\$>";
$shuzu1[11]="<=\$CityId\$>";
$shuzu1[12]="width=\"100%\"";
$MyMake->OutUrl="News_show_1.shtml";
$shuzu2[0]="数组0";
$shuzu2[1]="数组1";
$shuzu2[2]="数组2";
$shuzu2[3]="数组3";
$shuzu2[4]="数组4";
$shuzu2[5]="数组5";
$shuzu2[6]="数组6";
$shuzu2[7]="数组7";
$shuzu2[8]="数组8";
$shuzu2[9]="数组9";
$shuzu2[10]="数组10";
$shuzu2[11]="数组11";
$shuzu2[12]="width=\"95%\"";
$MyMake->Replacehtml($shuzu1,$shuzu2);
$MyMake->SaveFile();
//------------------静态生成完成-----------

猜你在找的PHP相关文章