php小偷之定时生成html

程序代码 程序代码
<?php

if(file_exists("cache/list_$htmlnum.txt"))//看静态index.htm文件是否存在
{
$time=time();

//文件修改时间和现在时间相差?的话,直接导向htm文件,否则重新生成htm
if($time-filemtime("cache/list_$htmlnum.txt")<600)
{
    echo file_get_contents("cache/list_$htmlnum.txt");
    exit;
}
}
//在你的开始处加入ob_start();
ob_start();

//缓存内容开始

//要缓存的内容


//缓存内容结束

//在结尾加入ob_end_clean(),并把本页输出到一个变量中
$temp=ob_get_contents();
ob_end_clean();

//写入文件
$fp=fopen("cache/list_$htmlnum.txt",'w');
fwrite($fp,$temp) or die('写文件错误');
echo $temp;
//echo "生成HTML完成!";
?>


[本日志由 shao65308 于 2009-09-25 09:49 PM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: PHP
相关日志:
评论: 0 | 引用: 0 | 查看次数: 2960
发表评论
你没有权限发表评论!