Home > php教程 > php手册 > PHP静态文件生成类实例

PHP静态文件生成类实例

WBOY
Release: 2016-06-06 20:16:30
Original
1278 people have browsed it

这篇文章主要介绍了PHP静态文件生成类,以实例形式演示了PHP生成静态文件的方法,并封装成类文件便于使用,是非常实用的技巧,需要的朋友可以参考下

本文实例讲述了PHP静态文件生成类。分享给大家供大家参考。

具体实现代码如下:

复制代码 代码如下:

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();
?>

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template