Use PHP to generate static HTML documents. Code: Copy the code as follows :? Php introduces the database configuration FILE include (dirname (_ FILE _). includeconfig. php); ***** generate a single code for the articles in the database:
The code is as follows:
// Introduce the database configuration file
Include (dirname (_ FILE _). "\ include \ config. php ");
/**
*
* Generate a single HTML file from the database.
* @ Param Date $ Date
* @ Param Time $ Time
* @ Param String $ Content
* @ Param String $ Title
*/
Function GenerateHTML ($ Date, $ Time, $ Content, $ Title, $ Name ){
// Splits the date and time variables into arrays.
$ GetDateRow = explode ("-", $ Date );
$ GetTimeRow = explode (":", $ Time );
// Obtain the file name. For example: 20121028210632.html
$ FileName = $ GetDateRow [0]. $ GetDateRow [1]. $ GetDateRow [2]. $ GetTimeRow [0]. $ GetTimeRow [1]. $ GetTimeRow [2]. ". html ";
// Open and read the template content
$ FP = fopen ("tmp.html", "r ");
$ Str = fread ($ FP, filesize ("tmp.html "));
// Get the replaced Template content
$ Str = str_replace ("{Title}", $ Title, $ Str );
$ Str = str_replace ("{Content}", $ Content, $ Str );
$ Str = str_replace ("{Name}", $ Name, $ Str );
$ Str = str_replace ("{Date}", $ Date, $ Str );
$ Str = str_replace ("{Time}", $ Time, $ Str );
// Close the file to reduce the pressure on the server.
Fclose ($ FP );
// Write the content to an HTML file
$ Handle = fopen ($ FileName, "w ");
Fwrite ($ Handle, $ Str );
Fclose ($ Handle );
// Perform a minor test
// Echo "OK, done! ";
}
// Database operations
$ Querysql = "select * from article ";
$ Queryset = mysql_query ($ querysql );
// Generate HTML files cyclically.
While ($ row = mysql_fetch_array ($ queryset )){
GenerateHTML ($ row ['Date'], $ row ['Time'], $ row ['content'], $ row ['title'], $ row ['name']);
}
The pipeline code is as follows :? Php // introduce the database configuration FILE include (dirname (_ FILE __)). "\ include \ config. php ");/*** generate a single article in the database...