萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php簡單生成html靜態頁面代碼

php簡單生成html靜態頁面代碼

這是一款我自己沒事時寫的一款簡單的把php文件生成html靜態頁面的程序代碼哦,就是用str_replace來替換函數返回的數據就OK了。

$fileName = md5_filename($rs[0],$rs['z_a'],$rs['filesendid']);
   $path = get_path($rs['sysa']).$rs['z_a'].'/';
     
   $parent = $_SERVER["DOCUMENT_ROOT"];//substr(getcwd(),0,strrpos(getcwd(),'\'));  
    
   $filePath = $parent.'\'.$path;
   $tempLate = str_replace('{path}',path($rs['z_a'],$rs['sysa']),$fileContent);
   $tempLate = str_replace('{htmlAbout}',htmlAbout($rs['z_a'],10,8,0,''),$tempLate);   
   $tempLate = str_replace('{htmlTemplate}',htmlTemplate(0),$tempLate);
   $tempLate = str_replace('{htmlMenu}',htmlMenu($rs['sysa']),$tempLate);
   $tempLate = str_replace('{htmlHelp}',htmlHelp($rs['sysa']),$tempLate);
   $tempLate = str_replace('{htmlNews}',htmlAbout($rs['z_a'],0,8,0,''),$tempLate);
   $tempLate = str_replace('{htmlHot}',htmlAbout($rs['z_a'],0,8,1,''),$tempLate);
   $tempLate = str_replace('{htmlSoure}',htmlTemplate(1),$tempLate);
   $tempLate = str_replace('php簡單生成html靜態頁面代碼',$rs['title'],$tempLate);
   $tempLate = str_replace('{htmlContent}',$rs['content'],$tempLate);
   $tempLate = str_replace('{description}',$rs['description'],$tempLate);
   $tempLate = str_replace('{keywords}',$rs['keywords'],$tempLate);
   makeHtml($tempLate,$filePath,$fileName);

function makeHtml($msgContent,$filePath,$fileName){//生成html文件  
  if(!is_dir($filePath)){@mkdir($filePath);} 
  //die($filePath);   
  $handle = fopen(str_replace('\','../',$filePath.$fileName),'w+') or die("can't create file!$fileName");
  fwrite($handle,$msgContent);
  fclose($handle);  
}

本站原創轉截注明:www.111cn.net/phper/php.html

copyright © 萬盛學電腦網 all rights reserved