php產生靜態頁面函數(php2html)的例子

來源:互聯網
上載者:User
  1. /**
  2. ------------------------
  3. Function: php2html($in_Url, $out_htmlFile, $out_logFile)
  4. ------------------------
  5. @ Description: 產生靜態函數
  6. @ Copyright: Copyright (c) 2006 - 2011
  7. @ Create: 2006-08-01
  8. @ Modify: 2013-02-16
  9. @ 提示:路徑為伺服器絕對路徑; 若給定的路徑目錄不存在則自動建立
  10. @ Example:php2html("http://bbs.it-home.org", "/www/html/index.html", "/www/log/log.txt");
  11. */
  12. // {{{ contents
  13. function php2html($in_Url, $out_htmlFile, $out_logFile)
  14. {
  15. $htmlContent = file_get_contents($in_Url); //將檔案讀入 $htmlContent 變數
  16. /**
  17. * @檢查要產生的檔案是否存在
  18. */
  19. if (is_file($out_htmlFile))
  20. {
  21. @unlink($out_htmlFile);//若檔案已存在,則刪除
  22. }
  23. /**
  24. * @ 建立目錄 網頁部分
  25. */
  26. $dir_array = explode("/", dirname($out_htmlFile));
  27. chdir("/"); //改變目錄到根
  28. for($i=1;$i{
  29. if(is_dir($dir_array[$i]))
  30. {
  31. chdir($dir_array[$i]);
  32. }
  33. else
  34. {
  35. mkdir($dir_array[$i]);
  36. chdir($dir_array[$i]);
  37. }
  38. }
  39. /**
  40. * @ 建立目錄 日誌部分
  41. */
  42. $dir_array = explode("/", dirname($out_logFile));
  43. chdir("/"); //改變目錄到根
  44. for($i=1;$i{
  45. if(is_dir($dir_array[$i]))
  46. {
  47. chdir($dir_array[$i]);
  48. }
  49. else
  50. {
  51. mkdir($dir_array[$i], 0777);
  52. chdir($dir_array[$i]);
  53. }
  54. }
  55. $handle = fopen($out_htmlFile, "w"); //開啟檔案指標,建立檔案
  56. $logHandle = fopen ($out_logFile, "a+"); //開啟記錄檔
  57. /**
  58. * @檢查目錄是否可寫
  59. */
  60. if (!is_writable($out_htmlFile))
  61. {
  62. echo "檔案:".$out_htmlFile."不可寫,請檢查目錄屬性後重試";
  63. exit();
  64. }
  65. if (!is_writable($out_logFile))
  66. {
  67. echo "檔案:".$out_logFile."不可寫,請檢查目錄屬性後重試";
  68. exit();
  69. }
  70. /**
  71. * @寫入檔案
  72. */
  73. if (!fwrite ($handle, $htmlContent))
  74. {
  75. $logMsg = "寫入檔案" . $out_htmlFile . "失敗";
  76. }
  77. else
  78. {
  79. $logMsg = "建立檔案" . $out_htmlFile . "成功";
  80. }
  81. /**
  82. * @記錄日誌
  83. */
  84. $logMsg .= "(".date("Y-m-d H:i:s") .")\r\n";
  85. fwrite ($logHandle, $logMsg);
  86. fclose($logHandle); //關閉日誌指標
  87. fclose ($handle); //關閉指標
  88. }
  89. // }}}
  90. php2html("http://bbs.it-home.org", dirname(__FILE__)."/yanjing_html/index.html", dirname(__FILE__)."/yanjing_log/log.txt");
  91. echo "成功";
  92. ?>
複製代碼

您可能感興趣的文章:php產生靜態頁面的三種方法與代碼詳解php產生靜態頁面的方法(三個函數)php產生html靜態頁面的方法參考php寫的一個產生靜態頁面的類將資料庫中的所有內容產生html靜態頁面的代碼虛擬機器主機上定時自動產生靜態頁面的方法php產生靜態頁面的詳細教程apache中訪問不了偽靜態頁面的解決方案php寫的關於靜態頁面的蜘蛛爬行記錄的代碼smarty產生靜態頁面的方法PHP產生靜態頁面的方法apache訪問不了偽靜態頁面的解決方案

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.