This article mainly introduces the PHP static file generation class. It demonstrates the PHP static file generation method in the form of an instance and encapsulates it into class files for ease of use. It is a very practical technique, for more information, see
This article mainly introduces the PHP static file generation class. It demonstrates the PHP static file generation method in the form of an instance and encapsulates it into class files for ease of use. It is a very practical technique, for more information, see
This example describes the PHP static file generation class. Share it with you for your reference.
The specific implementation code is as follows:
The Code is 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. $ d;
$ A = explode ($ p, $ filePath );
Foreach ($ a as $ dir)
{
$ Path. = $ dir. $ p;
If (! Is_dir ($ path ))
{
// Echo 'This directory does not exist'. $ path;
Mkdir ($ path, 0755 );
}
}
Return $ filePath. $ p;
}
Function start ()
{
Ob_start ();
}
Function end ()
{
$ Info = ob_get_contents ();
$ FileId = '000000 ';
$ 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 usage is as follows:
The Code is as follows:
<? Php
$ S = new CreateHtml ();
$ S-> start ();
?>
Asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
Adfasdfasdf
>
<? Php
$ S-> end ();
?>
I hope this article will help you with PHP programming.
,