php2html php generating static page functions _php Tutorial

Source: Internet
Author: User
/**
------------------------
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 ...

  • 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.