PHP timed to automatically generate HTML static page
"Ob_start (), Ob_end_clean (), ob_get_contents ()"
Ob_start (): is to open the buffer, that is, you need to generate the contents of the static file cache here;
Ob_get_contents (): is read out of the buffer in the content, the following code for example;
Ob_end_clean (): This is more important, only after using this function, the contents of the buffer will be read out;
[Copy this Code] CODE:
if (File_exists ("./index.htm"))//See whether the static index.htm file exists
{
Time=time ();
File modification time and current time difference? If so, direct the HTM file, or regenerate HTM
if (Time-filemtime ("./index.htm") < 600)
{
Header ("location:classhtml/main.htm");
}
}
Add Ob_start () at the beginning of your service;
Ob_start ();
Home content, is your dynamic part of the
Add Ob_end_clean () at the end and output this page to a variable
Temp=ob_get_contents ();
Ob_end_clean ();
Write to File
Fp=fopen ("./index.htm", ' W ');
Fwrite (Fp,temp) or Die (' Write file error ');
echo "Generate HTML Finish!" ";