/**
------------------------
Function:php2html ($in _url, $out _htmlfile, $out _logfile)
------------------------
@ Description: Generate static function
@ copyright:copyright (c) 2006-2011
@ create:2006-08-01
@ modify:2006-10-27
@ Hint: The path to be used here is the absolute path of the server; Automatically created if the given path directory does not exist
=======================================================================================
@ example:php2html ("http://www.jb51.net", "/www/html/index.html", "/www/log/log.txt");
*/
{{{contents
function php2html ($in _url, $out _htmlfile, $out _logfile)
{
$htmlContent = file_get_contents ($in _url); Read a file into $htmlContent variable
/**
* @ Check if the file to be generated exists
*/
if (Is_file ($out _htmlfile))
{
@unlink ($out _htmlfile);//If the file already exists, delete
}
/**
* @ Create a catalog 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 Directory to 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 file pointer, create file
$logHandle = fopen ($out _logfile, "A +"); Open log File
/**
* @ Check if directory is writable
*/
if (!is_writable ($out _htmlfile))
{
echo "File:". $out _htmlfile. " Not writable, please check the directory properties and retry ";
Exit ();
}
if (!is_writable ($out _logfile))
{
echo "File:". $out _logfile. " Not writable, please check the directory properties and retry ";
Exit ();
}
/**
* @ Write file
*/
if (!fwrite ($handle, $htmlContent))
{
$LOGMSG = "Write file". $out _htmlfile. "Failure";
}
Else
{
$LOGMSG = "Create File". $out _htmlfile. "Success";
}
/**
* Record Log
*/
$logMsg. = "(". Date ("Y-m-d h:i:s"). ") \ r \ n ";
Fwrite ($logHandle, $LOGMSG);
Fclose ($logHandle); Close the log pointer
Fclose ($handle); Close pointer
}
// }}}
Php2html ("Http://www.jb51.net", DirName (__file__). " /yanjing_html/index.html ", DirName (__file__). /yanjing_log/log.txt ");
echo "Success";
?>
http://www.bkjia.com/PHPjc/319702.html www.bkjia.com true http://www.bkjia.com/PHPjc/319702.html techarticle ? PHP/**------------------------function:php2html ($in _url, $out _htmlfile, $out _logfile)---------------------- --@ Description: Generate static function @ Copyright:copyright (c) 2006 ...