Php static file generation class instance Analysis _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.