欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-05 21:21:58
复制代码 代码如下:/*********************/ /* */ /* version : 5.2.5 */ /* author : liqiangwork#...
复制代码 代码如下:

/*********************/
/* */
/* 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("<br>".$shuzusou(i)."=".$shuzuobj(i)."<br>")
}
}
//-----------------------------批量替换数组完成--------------------------
//-----------------------------读取文件---------------------------------
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);
}
//-----------------------------保存文件完成------------------------------
}
//------------------------------生成静态的类完成-------------------------------

相关实例:
1