PHP implements scheduled generation of HTML website homepage example code_PHP tutorial

WBOY
Release: 2016-07-21 15:48:19
Original
824 people have browsed it

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!";

www.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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!