-
- /**
- ------------------------
- Function: php2html($in_Url, $out_htmlFile, $out_logFile)
- ---------- --------------
- @ Description: Generate static function
- @ Copyright: Copyright (c) 2006 - 2011
- @ Create: 2006-08-01
- @ Modify: 2013-02-16
- @ Tip: The path is the absolute path of the server; if the given path directory does not exist, it will be 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);//If the file already exists, delete it
- }
- / **
- * @Create directory web page section
- */
- $dir_array = explode("/", dirname($out_htmlFile));
- chdir("/"); //Change directory to 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 section
- */
- $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 the file
- $logHandle = fopen ($out_logFile, "a+"); //Open the log file
- /**
- * @Check if the directory is writable
- */
- if (!is_writable($out_htmlFile))
- {
- echo "File: ".$out_htmlFile." is not writable, please check the directory attributes and try again";
- exit();
- }
- if (!is_writable($out_logFile))
- {
- echo "File:" .$out_logFile."Not writable, please check the directory attributes and try again";
- exit();
- }
- /**
- * @write file
- */
- if (!fwrite ($handle, $htmlContent))
- {
- $ logMsg = "Write file" . $out_htmlFile . "Failed";
- }
- else
- {
- $logMsg = "Create file" . $out_htmlFile . "Success";
- }
- /**
- * @record log
- */
- $ logMsg .= "(".date("Y-m-d H:i:s") .")rn";
- 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 "Success";
- ?>
Copy code
Articles you may be interested in:
Three methods and code details for generating static pages in PHP
How to generate static pages in php (three functions)
Reference on how to generate html static pages with php
A class written in php to generate static pages
Code to generate html static pages from all content in the database
How to automatically generate static pages on a virtual host at regular intervals
Detailed tutorial on generating static pages with php
Solution to the problem that pseudo-static pages cannot be accessed in apache
Code written by php about spider crawling records of static pages
How to generate static pages using smarty
How to generate static pages with PHP
Solution to the problem that apache cannot access pseudo-static pages
|