PHP static file generation class instance analysis, _php tutorial

Source: Internet
Author: User

PHP static file generation class instance analysis,


The example in this paper describes the PHP static file generation class. Share to everyone for your reference.

The implementation method is as follows:
Copy CodeThe 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 Two
if (File_exists ("./index.htm"))//See if the static index.htm file exists
{
$time =time ();
File modification time and current time difference?, direct-oriented HTM file, otherwise regenerate HTM
if (Time-filemtime ("./index.htm") < 600)
{
Header ("location:classhtml/main.htm");
}
}
Add Ob_start () at the beginning of your service;
Ob_start ();
The content of the homepage is your dynamic part.
Add Ob_end_clean () at the end and output this page to a variable
$temp =ob_get_contents ();
Ob_end_clean ();
Write file
$FP =fopen ("./index.htm", ' W ');
Fwrite (Fp,temp) or Die (' Write file error ');
echo "Generate HTML complete! ";

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/936795.html www.bkjia.com true http://www.bkjia.com/PHPjc/936795.html techarticle php static file generation class instance analysis, this article describes the PHP static file generation class. Share to everyone for your reference. Here's how to do this: Copy the code as follows: Def ...

  • Related Article

    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.