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 ...