您好,欢迎访问一九零五行业门户网

php 生成静态文件实例类函数

php 生成静态文件实例类函数
//-----------------------------生成静态的类-------------------------------
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=;
     $shuzu1=$value; 
     $i++;
      }
      $this->replacehtml(shuzu2,shuzu1);
      }
      //------------------自动获取要替换的字符串-------------------
    }
   //-----------------------------自动按字段替换完成------------------------
//-----------------------------批量替换数组--------------------------
   function replacehtml($shuzusou,$shuzuobj){  //批量替换数组
    if(count($shuzusou)!=count($shuzuobj)){
      exit(替换数组不匹配);
    }
    if($this->allhtml==){
      exit(没有要替换的内容);   
    }
    for($i=0;$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);
   }
   //-----------------------------保存文件完成------------------------------
}
实例
$mymake->mburl=news_show.shtml;
     $mymake->readfile();
     $thtml=$mymake->allhtml;
     $shuzu1=array();
     $shuzu2=array();
     $shuzu1[0]=;
     $shuzu1[1]=;
     $shuzu1[2]=;
     $shuzu1[3]=;
     $shuzu1[4]=;
     $shuzu1[5]=;
     $shuzu1[6]=;
     $shuzu1[7]=;
     $shuzu1[8]=;
     $shuzu1[9]=;
     $shuzu1[10]=;
     $shuzu1[11]=;
     $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();
其它类似信息

推荐信息