Php2html PHP static page generation function
Last Update:2018-12-08
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 ";
?>