Example of generating a static page function (php2html) using php
- /**
- ------------------------
- Function: php2html ($ in_Url, $ out_htmlFile, $ out_logFile)
- ------------------------
- @ Description: generate static functions
- @ Copyright: Copyright (c) 2006-2011
- @ Create: 2006-08-01
- @ Modify: 2013-02-16
- @ Prompt: The path is the absolute path of the server. if the specified path does not exist, it is automatically created.
- @ Example: php2html ("http://bbs.it-home.org", "/www/html/index.html", "/www/log/log.txt ");
- */
- // {Contents
- Function php2html ($ in_Url, $ out_htmlFile, $ out_logFile)
- {
- $ HtmlContent = file_get_contents ($ in_Url); // read the file into the $ htmlContent variable
- /**
- * @ Check whether the file to be generated exists
- */
- If (is_file ($ out_htmlFile ))
- {
- @ Unlink ($ out_htmlFile); // delete a file if it already exists
- }
- /**
- * @ Create a directory webpage
- */
- $ Dir_array = explode ("/", dirname ($ out_htmlFile ));
- Chdir ("/"); // change the directory to the root
- For ($ I = 1; $ I {
- If (is_dir ($ dir_array [$ I])
- {
- Chdir ($ dir_array [$ I]);
- }
- Else
- {
- Mkdir ($ dir_array [$ I]);
- Chdir ($ dir_array [$ I]);
- }
- }
- /**
- * @ Create Directory log
- */
- $ Dir_array = explode ("/", dirname ($ out_logFile ));
- Chdir ("/"); // change the directory to the root
- For ($ I = 1; $ I {
- If (is_dir ($ dir_array [$ I])
- {
- Chdir ($ dir_array [$ I]);
- }
- Else
- {
- Mkdir ($ dir_array [$ I], 0777 );
- Chdir ($ dir_array [$ I]);
- }
- }
- $ Handle = fopen ($ out_htmlFile, "w"); // open the file pointer and create a file
- $ LogHandle = fopen ($ out_logFile, "a +"); // open the log file
- /**
- * @ Check whether the directory is writable
- */
- If (! Is_writable ($ out_htmlFile ))
- {
- Echo "File:". $ out_htmlFile. "the file cannot be written. check the directory properties and try again ";
- Exit ();
- }
- If (! Is_writable ($ out_logFile ))
- {
- Echo "File:". $ out_logFile. "cannot be written. check the directory properties and try again ";
- Exit ();
- }
- /**
- * @ Write file
- */
- If (! Fwrite ($ handle, $ htmlContent ))
- {
- $ LogMsg = "write file". $ out_htmlFile. "failed ";
- }
- Else
- {
- $ LogMsg = "create file". $ out_htmlFile. "successful ";
- }
- /**
- * @ Record logs
- */
- $ LogMsg. = "(". date ("Y-m-d H: I: s"). ") \ r \ n ";
- Fwrite ($ logHandle, $ logMsg );
- Fclose ($ logHandle); // Close the log pointer
- Fclose ($ handle); // Close the pointer
- }
- //}}}
- Php2html ("http://bbs.it-home.org", dirname (_ FILE _). "/yanjing_html/index.html", dirname (_ FILE _). "/yanjing_log/log.txt ");
- Echo "successful ";
- ?>
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 |