Php2html PHP static page generation function

Source: Internet
Author: User

<? PHP
/**
------------------------
Function: php2html ($ in_url, $ out_htmlfile, $ out_logfile)
------------------------
@ Description: generate static functions
@ Copyright: Copyright (c) 2006-2011
@ Create: 2006-08-01
@ Modify: 2006-10-27
@ Prompt: the path used here is the absolute server path. If the specified path does not exist, it is automatically created.
========================================================== ========================================================== ========
@ 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 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 <count ($ dir_array); $ 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 <count ($ dir_array); $ 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://www.jb51.net", dirname (_ file _). "/yanjing_html/index.html", dirname (_ file _). "/yanjing_log/log.txt ");
Echo "successful ";
?>

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.