復制代碼 代碼如下:
<?php
function CreateShtml()
{
ob_start("callback_CteateShtml");
}
function callback_CteateShtml($buffer)
{
$page = intval(@$_REQUEST["page"]);
//$fileName = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/article/" . basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".html";
$fileName = basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".html";//可以在這裡修改你的靜態頁面路徑
$fp = fopen($fileName,"wb");
fwrite($fp,$buffer);
fclose($fp);
return $buffer;
}
?>
舉個例
把上面的代碼保存為 static.php
執行下面頁面 phpfans.php
復制代碼 代碼如下:
<?php
include("static.php");
CreateShtml();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<body>
<?php
echo "歡迎你,http://www.jb51.net";
?>
</body>
</html>
將會生成一個 phpfans.html的靜態頁面
如果有參數,則用page來傳遞 如 phpfans.php?page=1
則生成 phpfans_1.html的靜態頁面