方法一,將本機(jī)或所在虛擬主機(jī)(站點(diǎn))的某個(gè)頁面生成HTML 引用時(shí)必段使用相對(duì)路徑,復(fù)制以下代碼,保存為yiskyphp.php,然后訪問url+yiskyphp.php如http://www.002bubu.com/yiskyphp.php
PHP代碼
- <?php
- $nowtime=time();
- $pastsec = $nowtime - $_GET["t"];
- if($pastsec<60)
- {
- exit; //1分鐘更新一次,時(shí)間可以自己調(diào)整
- }
- ob_start(); //打開緩沖區(qū)
- include("phpinfo.php");
- $content = ob_get_contents(); //得到緩沖區(qū)的內(nèi)容
- $content .= "<script language=javascript src='yiskyphp.php?t=".$nowtime."'></script>";
- file_put_contents("index.html",$content);
- if (!function_exists("file_put_contents"))
- {
- function file_put_contents($fn,$fs)
- {
- $fp=fopen($fn,"w+");
- fputs($fp,$fs);
- fclose($fp);
- }
- }
- ?>
方法二:將指定網(wǎng)頁中的內(nèi)容生成HTML,引用的地址需為直接地址。將文件保存為:php2html.php
PHP代碼
- <?php
- $nowtime=time();
- $pastsec = $nowtime - $_GET["t"];
- if($pastsec<60)
- {
- exit; //1分鐘更新一次,時(shí)間可以自己調(diào)整
- }
- $content = file_get_contents('http://www.002bubu.com/index.asp');//也可引用擴(kuò)展名為PHP的網(wǎng)頁
- $content=preg_replace("/[\r\n]+/", '', $content ); //是將回車去掉,此段可有可無,如影響使用請去除
- $content .= "<div style='display:none'>請注意此行代碼不要?jiǎng)h除 此為定時(shí)生成的必要代碼 亳州易天科技 WWW.002bubu.com PHP自動(dòng)生成HTML(PHP生成靜態(tài)面頁)實(shí)例</div><script language=javascript src='php2html.php?t=".$nowtime."'></script>";
- file_put_contents("index.html",$content);
- if (!function_exists("file_put_contents"))
- {
- function file_put_contents($fn,$fs)
- {
- $fp=fopen($fn,"w+");
- fputs($fp,$fs);
- fclose($fp);
- }
- }
- ?>