php 產生靜態檔案執行個體類函數

來源:互聯網
上載者:User

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="<=$".$key."$>";
     $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<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);
   }
   //-----------------------------儲存檔案完成------------------------------
}


執行個體

$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();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.