PHP generates code for static HTML documents for all content in the database _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
/*
Author:www.5dkx.com
Done: Generating HTML documents
Date:2009-10-27
*/
Require_once ("conn.php");
if ($_get[' all ')
{
/* Get database records 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 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 (" Open write file failed! ");
Fwrite ($FP, $fpcontent) or Die ("Write file failed!");
}
echo "";
}
if ($_get[' part ')
{
/* Gets the ID of the last record so that the generated HTML file has a file name */
$sqlquery = "SELECT * from $tbname the 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 (" Open write file failed! ");
Fwrite ($FP, $fpcontent) or Die ("Write file failed!");
echo "";
}
?>


<title>Generating HTML documents</title>



echo "All updates
Partial Update ";
?>


http://www.bkjia.com/PHPjc/321556.html www.bkjia.com true http://www.bkjia.com/PHPjc/321556.html techarticle Copy the code as follows: PHP/* author:www.5dkx.com done: Generate HTML Document DATE:2009-10-27 */require_once ("conn.php"), if ($_get[' all ') { /* Get database records for easy generation ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.