• 行業動態
    php生成HTML的兩種方法、PHP生成靜態頁的兩種方法
    發布日期:2013-01-16 閱讀次數:4030 字體大?。?a href="javascript:;" onclick="ChangeFontSize('content',16)">大

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

    PHP代碼
    1. <?php    
    2. $nowtime=time();    
    3. $pastsec = $nowtime - $_GET["t"];    
    4.   
    5. if($pastsec<60)    
    6. {    
    7. exit//1分鐘更新一次,時間可以自己調整    
    8. }    
    9.   
    10. ob_start(); //打開緩沖區    
    11. include("phpinfo.php");    
    12. $content = ob_get_contents(); //得到緩沖區的內容    
    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. ?>  

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

    PHP代碼
    1. <?php    
    2. $nowtime=time();    
    3. $pastsec = $nowtime - $_GET["t"];    
    4.   
    5. if($pastsec<60)    
    6. {    
    7. exit//1分鐘更新一次,時間可以自己調整    
    8. }    
    9.   
    10. $content = file_get_contents('http://m.abbyshandihome.com/index.asp');//也可引用擴展名為PHP的網頁    
    11. $content=preg_replace("/[\r\n]+/"''$content ); //是將回車去掉,此段可有可無,如影響使用請去除  
    12.   
    13. $content .= "<div style='display:none'>請注意此行代碼不要刪除 此為定時生成的必要代碼 亳州易天科技 m.abbyshandihome.com PHP自動生成HTML(PHP生成靜態面頁)實例</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. ?>  

     

    国产精品 高清 尿 小便 嘘嘘_无码8090精品久久一区_精品无码专区毛片_一本久道久久综合网