Home > Backend Development > PHP Tutorial > PHP generates code for static html documents from all content in the database_PHP tutorial

PHP generates code for static html documents from all content in the database_PHP tutorial

WBOY
Release: 2016-07-21 15:39:16
Original
1026 people have browsed it

Copy code The code is as follows:

/*
author:www.5dkx.com
done: Generate html document
date:2009-10-27
*/
require_once("conn.php");
if($_GET['all'])
{
/*Get the database record so that the generated html file has a file name*/
$sqlquery = "select * from $tbname";
$result = mysql_query($sqlquery,$conn)or die ("Query failed!");
$fp = fopen("./template/article.html",r);
$fpcontent = fread($fp,filesize("./template/article.html" "));
fclose($fp);
/*Write to file*/
while($row = mysql_fetch_array($result))
{
$fpcontent = str_replace(" {thetitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{chatitle}",$row['title'],$fpcontent);
$fpcontent = str_replace ("{bookcontent}",$row['content'],$fpcontent);
$fp = fopen("./html/".$row['id'].".html",w)or die("Failed to open the file for writing!");
fwrite($fp,$fpcontent)or die("Failed to open the file for writing!");
}
echo "";
}
if($_GET['part'])
{
/*Get the last record ID, so that the html file has a file name */
$sqlquery = "select * from $tbname order by id desc limit 1";
$result = mysql_query($sqlquery,$conn)or die( "Query failed!");
$row = mysql_fetch_array($result);
$fp = fopen("./template/article.html",r);
$fpcontent = fread($fp ,filesize("./template/article.html"));
fclose($fp);
$fpcontent = str_replace("{thetitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{chatitle}",$row['title'],$fpcontent);
$fpcontent = str_replace("{bookcontent}",$row['content'],$fpcontent );
$fp = fopen("./html/".$row['id'].".html",w)or die("Failed to open file for writing!");
fwrite( $fp,$fpcontent)or die("Failed to write file!");
echo "";
}
?>


Generate html document



echo "All updated
Partial update" ;
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321556.htmlTechArticleCopy the code as follows: ?php /* author:www.5dkx.com done:Generate html documentdate:2009 -10-27 */ require_once("conn.php"); if($_GET['all']) { /*Get database records to facilitate generation...
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