Code to generate HTML static pages for all content in the database

Source: Internet
Author: User
Tags fread php write
  1. Require_once ("conn.php");
  2. if ($_get[' all ')
  3. {
  4. /* Get database records so that the generated HTML file has a file name */
  5. $sqlquery = "SELECT * from $tbname";
  6. $result = mysql_query ($sqlquery, $conn) or Die ("Query failed!");
  7. $fp = fopen ("./template/article.html", R);
  8. $fpcontent = Fread ($fp, FileSize ("./template/article.html"));
  9. Fclose ($FP);
  10. /* Write file */
  11. while ($row = Mysql_fetch_array ($result))
  12. {
  13. $fpcontent = Str_replace ("{thetitle}", $row [' title '], $fpcontent);
  14. $fpcontent = Str_replace ("{chatitle}", $row [' title '], $fpcontent);
  15. $fpcontent = Str_replace ("{bookcontent}", $row [' content '], $fpcontent);
  16. $fp = fopen ("./html/". $row [' id ']. ". HTML ", W) or Die (" Open write file failed! ");
  17. Fwrite ($FP, $fpcontent) or Die ("Write file failed!");
  18. }
  19. echo "";
  20. }
  21. if ($_get[' part ')
  22. {
  23. /* Gets the ID of the last record, making it easy to generate an HTML file with a filename */
  24. $sqlquery = "SELECT * from $tbname the ORDER by id DESC limit 1";
  25. $result = mysql_query ($sqlquery, $conn) or Die ("Query failed!");
  26. $row = Mysql_fetch_array ($result);
  27. $fp = fopen ("./template/article.html", R);
  28. $fpcontent = Fread ($fp, FileSize ("./template/article.html"));
  29. Fclose ($FP);
  30. $fpcontent = Str_replace ("{thetitle}", $row [' title '], $fpcontent);
  31. $fpcontent = Str_replace ("{chatitle}", $row [' title '], $fpcontent);
  32. $fpcontent = Str_replace ("{bookcontent}", $row [' content '], $fpcontent);
  33. $fp = fopen ("./html/". $row [' id ']. ". HTML ", W) or Die (" Open write file failed! ");
  34. Fwrite ($FP, $fpcontent) or Die ("Write file failed!");
  35. echo "";
  36. }
  37. ?>
  38. Generate HTML
  39. echo "All updates
    Partial Update ";
  40. ?>
Copy Code

you may be interested in the article:three ways to generate static pages in PHP and the code in detail PHP generates static page functions (php2html) example PHP method for generating static pages (three functions) The template of PHP generated static files and cache PHP write a static page generated on the class virtual host on a regular basis to automatically generate static pages of PHP two ways to generate static files PHP generate static HTML file in a detailed tutorial PHP generates the Smarty static page method understanding PHP Generation Static H tml File principle Php method for generating static pages

  • 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.