Home >php教程 >php手册 >生成静态页面的php函数,php爱好者站推荐

生成静态页面的php函数,php爱好者站推荐

WBOY
WBOYOriginal
2016-06-13 12:32:481062browse

复制代码 代码如下:


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

复制代码 代码如下:


include("static.php"); 
CreateShtml(); 
?> 
 

 
 
无标题文档 
 
 
echo "脚本之家欢迎你,http://www.jb51.net"; 
?> 
 
  

将会生成一个 phpfans.html的静态页面
如果有参数,则用page来传递 如 phpfans.php?page=1
则生成 phpfans_1.html的静态页面
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn