Heim  >  Artikel  >  Backend-Entwicklung  >  将数据库中的所有内容生成html静态页面的代码

将数据库中的所有内容生成html静态页面的代码

WBOY
WBOYOriginal
2016-07-25 09:05:511287Durchsuche
  1. require_once("conn.php");
  2. if($_GET['all'])
  3. {
  4. /*获取数据库记录,以便于生成html文件有个文件名*/
  5. $sqlquery = "select * from $tbname";
  6. $result = mysql_query($sqlquery,$conn)or die("查询失败!");
  7. $fp = fopen("./template/article.html",r);
  8. $fpcontent = fread($fp,filesize("./template/article.html"));
  9. fclose($fp);
  10. /*写入文件*/
  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("打开写入文件失败!");
  17. fwrite($fp,$fpcontent)or die("写入文件失败!");
  18. }
  19. echo "";
  20. }
  21. if($_GET['part'])
  22. {
  23. /*获取最后一条记录的ID,便于生成html文件有个文件名*/
  24. $sqlquery = "select * from $tbname order by id desc limit 1";
  25. $result = mysql_query($sqlquery,$conn)or die("查询失败!");
  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("打开写入文件失败!");
  34. fwrite($fp,$fpcontent)or die("写入文件失败!");
  35. echo "";
  36. }
  37. ?>
  38. 生成html
  39. echo "全部更新
    部分更新";
  40. ?>
复制代码

您可能感兴趣的文章: php生成静态页面的三种方法与代码详解 php生成静态页面函数(php2html)的例子 php生成静态页面的方法(三个函数) 细说php生成静态文件之模板与缓存 php写的一个生成静态页面的类 虚拟主机上定时自动生成静态页面的方法 php生成静态文件的二种方法 php生成静态页面的详细教程 php生成静态html文件的原理分析 smarty生成静态页面的方法 了解php生成静态HTML文件的原理 PHP生成静态页面的方法



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn