Example of generating a static page function (php2html) using php

Source: Internet
Author: User
Tags php write
Example of generating a static page function (php2html) using php

  1. /**
  2. ------------------------
  3. Function: php2html ($ in_Url, $ out_htmlFile, $ out_logFile)
  4. ------------------------
  5. @ Description: generate static functions
  6. @ Copyright: Copyright (c) 2006-2011
  7. @ Create: 2006-08-01
  8. @ Modify: 2013-02-16
  9. @ Prompt: The path is the absolute path of the server. if the specified path does not exist, it is automatically created.
  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); // read the file into the $ htmlContent variable
  16. /**
  17. * @ Check whether the file to be generated exists
  18. */
  19. If (is_file ($ out_htmlFile ))
  20. {
  21. @ Unlink ($ out_htmlFile); // delete a file if it already exists
  22. }
  23. /**
  24. * @ Create a directory webpage
  25. */
  26. $ Dir_array = explode ("/", dirname ($ out_htmlFile ));
  27. Chdir ("/"); // change the directory to the root
  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. * @ Create Directory log
  41. */
  42. $ Dir_array = explode ("/", dirname ($ out_logFile ));
  43. Chdir ("/"); // change the directory to the root
  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"); // open the file pointer and create a file
  56. $ LogHandle = fopen ($ out_logFile, "a +"); // open the log file
  57. /**
  58. * @ Check whether the directory is writable
  59. */
  60. If (! Is_writable ($ out_htmlFile ))
  61. {
  62. Echo "File:". $ out_htmlFile. "the file cannot be written. check the directory properties and try again ";
  63. Exit ();
  64. }
  65. If (! Is_writable ($ out_logFile ))
  66. {
  67. Echo "File:". $ out_logFile. "cannot be written. check the directory properties and try again ";
  68. Exit ();
  69. }
  70. /**
  71. * @ Write file
  72. */
  73. If (! Fwrite ($ handle, $ htmlContent ))
  74. {
  75. $ LogMsg = "write file". $ out_htmlFile. "failed ";
  76. }
  77. Else
  78. {
  79. $ LogMsg = "create file". $ out_htmlFile. "successful ";
  80. }
  81. /**
  82. * @ Record logs
  83. */
  84. $ LogMsg. = "(". date ("Y-m-d H: I: s"). ") \ r \ n ";
  85. Fwrite ($ logHandle, $ logMsg );
  86. Fclose ($ logHandle); // Close the log pointer
  87. Fclose ($ handle); // Close the pointer
  88. }
  89. //}}}
  90. Php2html ("http://bbs.it-home.org", dirname (_ FILE _). "/yanjing_html/index.html", dirname (_ FILE _). "/yanjing_log/log.txt ");
  91. Echo "successful ";
  92. ?>

Articles that you may be interested in: three methods for generating static pages in php and detailed code of generating static pages in php (three functions) to generate html static pages in php, refer to a class written by php to generate html static pages for all the content in the database. on the VM, the code of html static pages is automatically generated in php. static page detailed tutorial apache cannot access pseudo static page solution php write about static page spider crawling record Code smarty generate static page method PHP generate static page method apache solution to access a pseudo-static page

Related Article

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.