This example describes the PHP static file generation class. Share to everyone for your reference.
The specific implementation code is as follows:
Copy Code code as follows:
<?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;
$a =explode ($p, $filePath);
foreach ($a as $dir)
{
$path. = $dir. $p;
if (!is_dir ($path))
{
Echo ' does not have this directory '. $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 ();
}
}
?>
The specific usage is as follows:
Copy Code code as follows:
<?php
$s =new createhtml ();
$s->start ();
?>
<body>
Asdfasdfasdfasdfasdfasdfasdfasdfasdf<br>
Adfasdfasdf<br>
</body>>
<?php
$s->end ();
?>
I hope this article will help you with your PHP program design.