PHP generates a static HTML document implementation code,
Use PHP to generate a single HTML document for the article data in the database. First, to facilitate the inclusion of search engines. Second, it is more secure to avoid exposing fields in the database to the Address bar.
Give the code:
<?php//introduces the database configuration file include (DirName (DirName (__file__)). \include\config.php ");/** * * Generates a single HTML file for the articles in the database. * @param Date $Date * @param time $Time * @param string $Content * @param string $Title */function generatehtml ($Date, $Tim E, $Content, $Title, $Name) {//Divide the date and time variables into groups $getdaterow = explode ("-", $Date); $GetTimeRow = Explode (":", $Time);// Get the name of the file. For example: 20121028210632.html$filename = $GetDateRow [0]. $GetDateRow [1]. $GetDateRow [2]. $GetTimeRow [0]. $GetTimeRow [1].$ GETTIMEROW[2]. ". HTML ";//Open and read the template contents $fp = fopen (" tmp.html "," R "), $Str = Fread ($FP, FileSize (" tmp.html ")),//Get the template content after replacement $str = Str_replace (" {Title} ", $Title, $Str); $Str = Str_replace (" {Content} ", $Content, $Str); $Str = Str_replace (" {Name} ", $Name, $Str); $Str = s Tr_replace ("{Date}", $Date, $Str), $Str = Str_replace ("{Time}", $Time, $STR);//Close the file to reduce the pressure on the server. Fclose ($FP);//writes the content to an HTML file $handle = fopen ($FileName, "w"); Fwrite ($Handle, $STR); fclose ($Handle);//Small Test//echo "OK, Done! ";} Operation of the database $querysql = "SELECT * from article"; $queryset = mysql_query ($querysql);//Loops through the generation of HTML files. while ($row = Mysql_fetch_array ($queryset)) {generatehtml ($row [' Date '], $row [' time '], $row [' content '], $row [' title '], $row [' name ']);}
The above is the whole content of this article, I hope that everyone's learning to help, but also hope that we support a lot of help the home.
http://www.bkjia.com/PHPjc/1136614.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136614.html techarticle PHP generates a static HTML document implementation code that uses PHP to generate a single HTML document for the article data in the database. First, to facilitate the inclusion of search engines. Second, avoid the database of ...