Before we start, let’s mention three functions: "ob_start(), ob_end_clean(), ob_get_contents()"
ob_start(): opens the buffer, which is to cache the content of the static file you need to generate in Here;
ob_get_contents(): is to read the contents of the buffer. The following code is an example;
ob_end_clean(): This is more important. Only after using this function, the contents of the buffer will be read. Take it out;
Copy code The code is as follows:
if(file_exists("./index.htm"))// Check whether the static index.htm file exists
{
time=time();
//If the file modification time is different from the current time?, direct to the htm file, otherwise regenerate the htm
if( time-filemtime("./index.htm")< 600)
{
header("Location:classhtml/main.htm");
}
}
//in Add ob_start() at the beginning;
ob_start();
//The content of the home page is your dynamic part
//Add ob_end_clean() at the end, and output this page to a variable Medium
temp=ob_get_contents();
ob_end_clean();
//Write file
fp=fopen("./index.htm",'w');
fwrite( fp,temp) or die('Error writing file');
//echo "Generating HTML completed!";
http://www.bkjia.com/PHPjc/319765.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319765.htmlTechArticle Before we start, let’s mention three functions: "ob_start(), ob_end_clean(), ob_get_contents()" ob_start(): opens the buffer, which is to buffer the content of the static file you need to generate...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn