国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php生成靜態頁面代碼

2024-05-04 21:48:56
字體:
來源:轉載
供稿:網友

本款生成靜態頁面程序實現原理是做好自定的模板標簽,然后由str_replace把標簽替換成指定的內容,再由fopen生成指定 文件名的靜態頁面,這樣就OK了,代碼如下:

  1. header('content-type:text/html;charset=utf-8'); 
  2. if(!function_exists('file_get_contents')){ //如果系統沒有file_get_contents()函數 
  3.  function file_get_contents($file){ //自己寫file_get_contents()函數 
  4.   $fp = fopen($file,'r'); 
  5.   $content = fread($fp,filesize($file)); 
  6.   fclose($fp); 
  7.   return $content
  8.  } 
  9. $tmp_file = 'template.html'//模板文件 
  10. $content = file_get_contents($tmp_file); //獲得模板文件內容 
  11. $title = 'title'//模板變量title要替換的值 
  12. $text = 'text'//模板變量text要替換的值 
  13. $content = str_replace('<{title}>',$title,$content); //替換模板變量title 
  14. $content = str_replace('<{text}>',$text,$content); //替換模板變量text 
  15. //echo $content; //顯示替換后的模板文件內容 
  16. makehtml('news.html',$content);//寫入生成后的靜態文件內容到news.html文件 
  17. echo '<a href="news.html" target="_blank">查看文件</a>'
  18. function makehtml($file,$content){ 
  19. //開源代碼Vevb.com 
  20.  $fp = fopen($file,'w'); 
  21.  fwrite($fp,$content); 
  22.  fclose($fp); 

template.html,代碼如下:

  1. <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  5. <title>makehtml</title> 
  6. </head> 
  7. <body> 
  8. 這是模板變量title------<{title}> 
  9. <br /> 
  10. 這是模板變量text------<{text}> 
  11. </body> 
  12. </html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大同县| 绥棱县| 洮南市| 防城港市| 临汾市| 镇坪县| 乐平市| 宁武县| 孟村| 同德县| 林口县| 申扎县| 凤阳县| 沈丘县| 保亭| 尼勒克县| 娄烦县| 娄烦县| 华亭县| 循化| 隆子县| 兴义市| 竹北市| 法库县| 茌平县| 定兴县| 龙岩市| 饶平县| 增城市| 共和县| 池州市| 西和县| 炎陵县| 东源县| 琼海市| 甘南县| 辽宁省| 唐山市| 漳平市| 宣威市| 孙吴县|