Php static file generation class instance analysis. Php static file generation instance analysis this article mainly introduces php static file generation class, and analyzes in detail the methods and usage techniques for generating static files using php in the form of instances, analysis of php static file generation class instances
This article mainly introduces the php static file generation class, and analyzes in detail the methods and usage skills for generating static files using php in the form of instances. For more information, see
This example describes the php static file generation class. Share it with you for your reference.
The specific implementation method is as follows:
The code is as follows:
Defined ('phpjb51') or die (header ("http/1.1 403 not forbidden "));
Class include_createstatic
{
Private $ htmlpath = '';
Private $ path = '';
Public $ monthpath = '';
Private $ listpath = '';
Private $ content = '';
Private $ filename = '';
Private $ extname = '.html ';
Public function createhtml ($ type, $ desname, $ content)
{
$ This-> htmlpath = getappinf ('htmlpath ');
If (! File_exists ($ this-> htmlpath ))
{
@ Mkdir ($ this-> htmlpath );
}
$ This-> path = $ this-> htmlpath. $ this-> monthpath .'/';
If (! File_exists ($ this-> path ))
{
@ Mkdir ($ this-> path );
}
$ This-> listpath = $ this-> htmlpath. 'list /';
If (! File_exists ($ this-> listpath ))
{
@ Mkdir ($ this-> listpath );
}
Switch ($ type)
{
Case 'index ':
$ This-> filename = $ desname;
Break;
Case 'List ':
$ This-> filename = $ this-> listpath. $ desname;
Break;
Case 'View ':
$ This-> filename = $ this-> path. $ desname;
Break;
}
$ This-> filename. = $ this-> extname;
$ This-> content = $ content;
}
Public function write ()
{
$ Fp = fopen ($ this-> filename, 'WB ');
If (! Is_writable ($ this-> filename ))
{
Return false;
}
If (! Fwrite ($ fp, $ this-> content ))
{
Return false;
}
Fclose ($ fp );
Return $ this-> filename;
}
}
// Method 2
If (file_exists ("./index.htm") // check whether the static index.htm file exists.
{
$ Time = time ();
// Is the file modification time different from the current time? Otherwise, the htm file will be generated again.
If (time-filemtime ("./index.htm") <600)
{
Header ("location: classhtml/main.htm ");
}
}
// Add ob_start () to your start ();
Ob_start ();
// The homepage content is your dynamic part
// Add ob_end_clean () to the end and output this page to a variable.
$ Temp = ob_get_contents ();
Ob_end_clean ();
// Write a file
$ Fp = fopen ("./index.htm", 'w ');
Fwrite (fp, temp) or die ('file writing error ');
// Echo "html generation complete! ";
I hope this article will help you with php programming.
This article introduces the php static file generation class. it analyzes in detail the methods and usage techniques for generating static files using php in the form of instances...