1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class CreateHtml
{
function mkdir($prefix = 'article'){
$y = date('Y');
$p = DIRECTORY_SEPARATOR;
$filePath = 'article' . $p . $y . $p . $p;
$a = explode($p, $filePath);
$path='';
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 = '.shtml';
$path = $this->mkdir($prefix = 'article');
$fileName = $fileId . $postfix;
$file = fopen($path . $fileName, 'w ');
fwrite($file, $info);
fclose($file);
ob_end_flush();
}
}

?>
<?php
$s = new CreateHtml();
$s->start();
?>
<html>
<body>
我是要输出的html页面代码, 你呢
</body>
</html>
<?php
$s->end();
?>