Give the code:
Copy CodeThe code is as follows:
Introducing a database configuration file
Include (DirName (DirName (__file__)). \include\config.php ");
/**
*
* Generate 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, $Time, $Content, $Title, $Name) {
Decompose 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 template content
$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 = Str_replace ("{Date}", $Date, $STR);
$STR = Str_replace ("{Time}", $Time, $STR);
Close the file and reduce the pressure on the server.
Fclose ($FP);
Writing content to an HTML file
$Handle = fopen ($FileName, "w");
Fwrite ($Handle, $STR);
Fclose ($Handle);
A little 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 ']);
}
http://www.bkjia.com/PHPjc/326180.html www.bkjia.com true http://www.bkjia.com/PHPjc/326180.html techarticle give the code: Copy the Code as follows:? PHP//Introduction Database configuration file include (DirName (DirName (__file__)). " \include\config.php "); /** * * To generate a single article in a database ...