- header(Content-type:text/html;charset=utf-8);
- if(!function_exists(file_get_contents)){ //如果系統沒有file_get_contents()函數
- function file_get_contents($file){ //自己寫file_get_contents()函數
- $fp = fopen($file,r);
- $content = fread($fp,filesize($file));
- fclose($fp);
- return $content;
- }
- }
- $tmp_file = template.html; //模板檔案
- $content = file_get_contents($tmp_file); //獲得模板檔案內容
- $title = title; //模板變數title要替換的值
- $text = text; //模板變數text要替換的值
- $content = str_replace(<{title}>,$title,$content); //替換模板變數title
- $content = str_replace(<{text}>,$text,$content); //替換模板變數text
- //echo $content; //顯示替換後的模板檔案內容
- MakeHtml(news.html,$content);//寫入產生後的靜態檔案內容到news.html檔案
- echo 查看檔案;
- function MakeHtml($file,$content){
- $fp = fopen($file,w);
- fwrite($fp,$content);
- fclose($fp);
- }
- ?>
http://www.bkjia.com/PHPjc/486247.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486247.htmlTechArticle?php header(Content-type:text/html;charset=utf-8); if(!function_exists(file_get_contents)){ //如果系統沒有file_get_contents()函數 function file_get_contents($file){ //自己寫...