首页 >php教程 >php手册 >如何用PHP实现新闻列表自动生成代码的效果

如何用PHP实现新闻列表自动生成代码的效果

PHPz
PHPz原创
2016-06-13 12:31:552045浏览

这篇文章主要讲了如何用PHP实现新闻列表自动生成代码的效果,有一定一定的参考价值,感兴趣的朋友可以看看。

function CreateShtml()  
{  
ob_start(array("callback_CreateShtml","callback_GoToShtml"));  
}  
function callback_CreateShtml($buffer)  
{  
$page = intval(@$_REQUEST["page"]);  
$fileName = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";  
$fp = fopen($fileName,"wb");  
fwrite($fp,$buffer);  
fclose($fp);  
return $buffer;  
}  
function callback_GoToShtml($buffer)  
{  
$page = intval(@$_REQUEST["page"]);  
$fileName = basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";  
header("location:" . $fileName);  
return $buffer;  
}  
function GoToShtml()  
{  
$page = intval(@$_REQUEST["page"]);  
$fileName = basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";  
if(file_exists($fileName))  
header("location:" . $fileName);  
}  
function DeleteShtml($fileName=NULL)  
{  
if(is_null($fileName))  
$fileName = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF'];  
if($fileName[0]=="/")  
$fileName = $_SERVER['DOCUMENT_ROOT'] . $fileName;  
$path = dirname($fileName);  
$dir = dir($path);  
$patten = "/^" . basename($fileName, ".php") . "(_[0-9]+)?.htm/";  
while(($entry = $dir->read())!==false)  
{  
if(is_file($path . "/" .$entry) && preg_match($patten,$entry))  
unlink ($path . "/" . $entry);  
}  
}

【相关教程推荐】

1. php编程从入门到精通全套视频教程
2. php从入门到精通 
3. bootstrap教程

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn