php2html PHP generates static page functions _php tips
Last Update:2017-01-19
Source: Internet
Author: User
<?php
/**
------------------------
Function:php2html ($in _url, $out _htmlfile, $out _logfile)
------------------------
@ Description: Generating static functions
@ copyright:copyright (c) 2006-2011
@ create:2006-08-01
@ modify:2006-10-27
@ Hint: The path to use here is the server absolute path; Automatically created if a 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 a $htmlContent variable
/**
* @ Check to see if the file is being generated
*/
if (Is_file ($out _htmlfile))
{
@unlink ($out _htmlfile);//If the file already exists, delete
}
/**
* @ Create Directory page section
*/
$dir _array = Explode ("/", DirName ($out _htmlfile));
ChDir ("/"); Change Directory to 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 section
*/
$dir _array = Explode ("/", DirName ($out _logfile));
ChDir ("/"); Change Directory to 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 file pointer, create file
$logHandle = fopen ($out _logfile, "A +"); Open log File
/**
* Check whether the directory can be written
*/
if (!is_writable ($out _htmlfile))
{
echo "File:". $out _htmlfile. " Not writable, please check the directory properties and try again.
Exit ();
}
if (!is_writable ($out _logfile))
{
echo "File:". $out _logfile. " Not writable, please check the directory properties and try again.
Exit ();
}
/**
* @ Write to File
*/
if (!fwrite ($handle, $htmlContent))
{
$LOGMSG = "Write to 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); Turn off 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";
?>