Home > Backend Development > PHP Tutorial > php2html php generates static page function_PHP tutorial

php2html php generates static page function_PHP tutorial

WBOY
Release: 2016-07-21 15:48:30
Original
882 people have browsed it

/**
---------------------
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
@ Tip: The path to be used here is the absolute path of the server; if the given path directory does not exist, it will be 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); //If the file already exists, delete
}
/**
* @Create directory web page section
*/
$dir_array = explode("/", dirname($out_htmlFile));
chdir("/ "); //Change the directory to the 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 the directory to the 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 the file pointer and create the file
$logHandle = fopen ($out_logFile, "a+"); //Open the log file
/**
* @Check if the directory is writable
*/
if (!is_writable($out_htmlFile))
{
echo "File: ".$out_htmlFile." Not writable, please check the directory attributes and try again";
exit();
}
if (!is_writable($out_logFile))
{
echo "File: ".$out_logFile ."Not writable, please check the directory attributes and try again";
exit();
}
/**
* @write file
*/
if (!fwrite ($handle, $htmlContent) )
{
$logMsg = "Write file" . $out_htmlFile . "Failed";
}
else
{
$logMsg = "Create file" . $out_htmlFile . "Success";
}
/**
* @record log
*/
$logMsg .= "(".date("Y-m-d H:i:s") .")rn";
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 "Success ";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319702.htmlTechArticle?php /** ------------------- ----- Function: php2html($in_Url, $out_htmlFile, $out_logFile) -------------------------- @ Description: Generate static function @ Copyright : Copyright (c) 2006...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template