时间:2021-07-01 10:21:17 帮助过:25人阅读
输出。
ob_start();#开启服务器缓存
include_once 'Index.php';
$ctx=ob_get_contents();#获取缓存
ob_end_clean();#清空缓存
$fh=fopen("index.html","w+");
fwrite($fh,$ctx);#写入html,生成html
fclose($fh);
/*
1、Flush:刷新缓冲区的内容,
class CreateHtml
{
function mkdir( $prefix= 'article' )
{
$y = date('Y');
$m = date('m');
$d = date('d');
$p=DIRECTORY_SEPARATOR;
$filePath='article'.$p.$y.$p.$m.$p.$d;
$a=explode($p,$filePath);
foreach ( $a as $dir)
{
$path.=$dir.$p;
if(!is_dir($path))
{
//echo '没有这个目录'.$path;
mkdir($path,0755);
}
}
return $filePath.$p;
}
function start()
{
ob_start();
}
function end()
{
$info = ob_get_contents();
$fileId = '12345';
$postfix = '.html';
$path = $this->mkdir($prefix= 'article');
$fileName = time().'_'.$fileId.$postfix;
$file=fopen($path.$fileName,'w+');
fwrite($file,$info);
fclose($file);
ob_end_flush();
}
}
?>
$s=new CreateHtml();
$s->start();
?>
asdfasdfasdfasdfasdfasdfasdfasdfasdf
adfasdfasdf
>
$s->end();
?>