Heim >php教程 >php手册 >PHP静态文件生成类

PHP静态文件生成类

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-22 18:36:24844Durchsuche

<?php
class CreateHtml {
    function mkdir($prefix = &#39;article&#39;) {
        $y = date(&#39;Y&#39;);
        $m = date(&#39;m&#39;);
        $d = date(&#39;d&#39;);
        $p = DIRECTORY_SEPARATOR;
        $filePath = &#39;article&#39; . $p . $y . $p . $m . $p . $d;
        $a = explode($p, $filePath);
        foreach ($a as $dir) {
            $path.= $dir . $p;
            if (!is_dir($path)) {
                //echo &#39;没有这个目录&#39;.$path;
                mkdir($path, 0755);
            }
        }
        return $filePath . $p;
    }
    function start() {
        ob_start();
    }
    function end() {
        $info = ob_get_contents();
        $fileId = &#39;12345&#39;;
        $postfix = &#39;.html&#39;;
        $path = $this->mkdir($prefix = &#39;article&#39;);
        $fileName = time() . &#39;_&#39; . $fileId . $postfix;
        $file = fopen($path . $fileName, &#39;w &#39;);
        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();
?>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php FreeBSD系统探测程序 Nächster Artikel:视频网站的制作例子二