成人国产一区二区三区|亚洲观看视频一级精品|亚洲综合人成网免费视频|99亚洲精品高清一二区|无码AV中文一区二区三区|精品色欧美色国产一区国产|国产午夜精品理论片在线观看|日本精品一区二区三区不卡观看

行業(yè)動態(tài)
php生成HTML的兩種方法、PHP生成靜態(tài)頁的兩種方法
發(fā)布日期:2013-01-16 閱讀次數(shù):3826 字體大小:

方法一,將本機或所在虛擬主機(站點)的某個頁面生成HTML 引用時必段使用相對路徑,復制以下代碼,保存為yiskyphp.php,然后訪問url+yiskyphp.php如http://m.lescaledessaveurs.com/yiskyphp.php

PHP代碼
  1. <?php    
  2. $nowtime=time();    
  3. $pastsec = $nowtime - $_GET["t"];    
  4.   
  5. if($pastsec<60)    
  6. {    
  7. exit//1分鐘更新一次,時間可以自己調(diào)整    
  8. }    
  9.   
  10. ob_start(); //打開緩沖區(qū)    
  11. include("phpinfo.php");    
  12. $content = ob_get_contents(); //得到緩沖區(qū)的內(nèi)容    
  13. $content .= "<script language=javascript src='yiskyphp.php?t=".$nowtime."'></script>";   
  14.   
  15. file_put_contents("index.html",$content);    
  16.   
  17. if (!function_exists("file_put_contents"))    
  18. {    
  19. function file_put_contents($fn,$fs)    
  20. {    
  21. $fp=fopen($fn,"w+");    
  22. fputs($fp,$fs);    
  23. fclose($fp);    
  24. }    
  25. }    
  26.   
  27. ?>  

方法二:將指定網(wǎng)頁中的內(nèi)容生成HTML,引用的地址需為直接地址。將文件保存為:php2html.php

PHP代碼
  1. <?php    
  2. $nowtime=time();    
  3. $pastsec = $nowtime - $_GET["t"];    
  4.   
  5. if($pastsec<60)    
  6. {    
  7. exit//1分鐘更新一次,時間可以自己調(diào)整    
  8. }    
  9.   
  10. $content = file_get_contents('http://m.lescaledessaveurs.com/index.asp');//也可引用擴展名為PHP的網(wǎng)頁    
  11. $content=preg_replace("/[\r\n]+/"''$content ); //是將回車去掉,此段可有可無,如影響使用請去除  
  12.   
  13. $content .= "<div style='display:none'>請注意此行代碼不要刪除 此為定時生成的必要代碼 亳州易天科技 m.lescaledessaveurs.com PHP自動生成HTML(PHP生成靜態(tài)面頁)實例</div><script language=javascript src='php2html.php?t=".$nowtime."'></script>";   
  14.   
  15. file_put_contents("index.html",$content);    
  16.   
  17. if (!function_exists("file_put_contents"))    
  18. {    
  19. function file_put_contents($fn,$fs)    
  20. {    
  21. $fp=fopen($fn,"w+");    
  22. fputs($fp,$fs);    
  23. fclose($fp);    
  24. }    
  25. }    
  26.   
  27. ?>