首页 > php代码 > 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();
    }
}
?>
<?php
    $s=new CreateHtml();
    $s->start();
?>
<html>
<body>
asdfasdfasdfasdfasdfasdfasdfasdfasdf<br>
adfasdfasdf<br>
</body>>
</html>
<?php
    $s->end();
?>


教程网址:http://www.phprm.com/code/b21cff279c9def1de2a480eb3b4575c1.html

欢迎收藏∩_∩但请保留本文链接。

标签:none

发表留言