PHP静态文件生成类实例
本文实例讲述了PHP静态文件生成类。分享给大家供大家参考。
具体实现代码如下:
<?php
classCreateHtml
{
functionmkdir($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($aas$dir)
{
$path.=$dir.$p;
if(!is_dir($path))
{
//echo'没有这个目录'.$path;
mkdir($path,0755);
}
}
return$filePath.$p;
}
functionstart()
{
ob_start();
}
functionend()
{
$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();
}
}
?>具体用法如下:
<?php $s=newCreateHtml(); $s->start(); ?> <html> <body> asdfasdfasdfasdfasdfasdfasdfasdfasdf<br> adfasdfasdf<br> </body>> </html> <?php $s->end(); ?>
希望本文所述对大家的PHP程序设计有所帮助。
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短