php2html php生成靜態(tài)頁函數(shù)
更新時間:2008年12月08日 00:34:50 作者:
生成靜態(tài)函數(shù) 這里要用到的路徑為服務器絕對路徑; 若給定的路徑目錄不存在則自動創(chuàng)建
<?php
/**
------------------------
Function: php2html($in_Url, $out_htmlFile, $out_logFile)
------------------------
@ Description: 生成靜態(tài)函數(shù)
@ Copyright: Copyright (c) 2006 - 2011
@ Create: 2006-08-01
@ Modify: 2006-10-27
@ 提示:這里要用到的路徑為服務器絕對路徑; 若給定的路徑目錄不存在則自動創(chuàng)建
=======================================================================================
@ Example:php2html("http://www.dhdzp.com", "/www/html/index.html", "/www/log/log.txt");
*/
// {{{ contents
function php2html($in_Url, $out_htmlFile, $out_logFile)
{
$htmlContent = file_get_contents($in_Url); //將文件讀入 $htmlContent 變量
/**
* @檢查要生成的文件是否存在
*/
if (is_file($out_htmlFile))
{
@unlink($out_htmlFile);//若文件已存在,則刪除
}
/**
* @ 創(chuàng)建目錄 網(wǎng)頁部分
*/
$dir_array = explode("/", dirname($out_htmlFile));
chdir("/"); //改變目錄到根
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]);
}
}
/**
* @ 創(chuàng)建目錄 日志部分
*/
$dir_array = explode("/", dirname($out_logFile));
chdir("/"); //改變目錄到根
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"); //打開文件指針,創(chuàng)建文件
$logHandle = fopen ($out_logFile, "a+"); //打開日志文件
/**
* @檢查目錄是否可寫
*/
if (!is_writable($out_htmlFile))
{
echo "文件:".$out_htmlFile."不可寫,請檢查目錄屬性后重試";
exit();
}
if (!is_writable($out_logFile))
{
echo "文件:".$out_logFile."不可寫,請檢查目錄屬性后重試";
exit();
}
/**
* @寫入文件
*/
if (!fwrite ($handle, $htmlContent))
{
$logMsg = "寫入文件" . $out_htmlFile . "失敗";
}
else
{
$logMsg = "創(chuàng)建文件" . $out_htmlFile . "成功";
}
/**
* @記錄日志
*/
$logMsg .= "(".date("Y-m-d H:i:s") .")\r\n";
fwrite ($logHandle, $logMsg);
fclose($logHandle); //關(guān)閉日志指針
fclose ($handle); //關(guān)閉指針
}
// }}}
php2html("http://www.dhdzp.com", dirname(__FILE__)."/yanjing_html/index.html", dirname(__FILE__)."/yanjing_log/log.txt");
echo "成功";
?>
/**
------------------------
Function: php2html($in_Url, $out_htmlFile, $out_logFile)
------------------------
@ Description: 生成靜態(tài)函數(shù)
@ Copyright: Copyright (c) 2006 - 2011
@ Create: 2006-08-01
@ Modify: 2006-10-27
@ 提示:這里要用到的路徑為服務器絕對路徑; 若給定的路徑目錄不存在則自動創(chuàng)建
=======================================================================================
@ Example:php2html("http://www.dhdzp.com", "/www/html/index.html", "/www/log/log.txt");
*/
// {{{ contents
function php2html($in_Url, $out_htmlFile, $out_logFile)
{
$htmlContent = file_get_contents($in_Url); //將文件讀入 $htmlContent 變量
/**
* @檢查要生成的文件是否存在
*/
if (is_file($out_htmlFile))
{
@unlink($out_htmlFile);//若文件已存在,則刪除
}
/**
* @ 創(chuàng)建目錄 網(wǎng)頁部分
*/
$dir_array = explode("/", dirname($out_htmlFile));
chdir("/"); //改變目錄到根
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]);
}
}
/**
* @ 創(chuàng)建目錄 日志部分
*/
$dir_array = explode("/", dirname($out_logFile));
chdir("/"); //改變目錄到根
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"); //打開文件指針,創(chuàng)建文件
$logHandle = fopen ($out_logFile, "a+"); //打開日志文件
/**
* @檢查目錄是否可寫
*/
if (!is_writable($out_htmlFile))
{
echo "文件:".$out_htmlFile."不可寫,請檢查目錄屬性后重試";
exit();
}
if (!is_writable($out_logFile))
{
echo "文件:".$out_logFile."不可寫,請檢查目錄屬性后重試";
exit();
}
/**
* @寫入文件
*/
if (!fwrite ($handle, $htmlContent))
{
$logMsg = "寫入文件" . $out_htmlFile . "失敗";
}
else
{
$logMsg = "創(chuàng)建文件" . $out_htmlFile . "成功";
}
/**
* @記錄日志
*/
$logMsg .= "(".date("Y-m-d H:i:s") .")\r\n";
fwrite ($logHandle, $logMsg);
fclose($logHandle); //關(guān)閉日志指針
fclose ($handle); //關(guān)閉指針
}
// }}}
php2html("http://www.dhdzp.com", dirname(__FILE__)."/yanjing_html/index.html", dirname(__FILE__)."/yanjing_log/log.txt");
echo "成功";
?>
您可能感興趣的文章:
- PHP中批量生成靜態(tài)html(命令行下運行PHP)
- php生成靜態(tài)頁面的簡單示例
- PHP 動態(tài)生成靜態(tài)HTML頁面示例代碼
- PHP中實現(xiàn)生成靜態(tài)文件的方法緩解服務器壓力
- 解析PHP生成靜態(tài)html文件的三種方法
- 基于PHP生成靜態(tài)頁的實現(xiàn)方法
- php添加文章時生成靜態(tài)HTML文章的實現(xiàn)代碼
- 利用PHP生成靜態(tài)HTML文檔的原理
- php生成靜態(tài)文件的多種方法分享
- 比較詳細PHP生成靜態(tài)頁面教程
- 用php的ob_start來生成靜態(tài)頁面的方法分析
- PHP定時自動生成靜態(tài)HTML的實現(xiàn)代碼
- php將數(shù)據(jù)庫中所有內(nèi)容生成靜態(tài)html文檔的代碼
- 通用PHP動態(tài)生成靜態(tài)HTML網(wǎng)頁的代碼
- php 生成靜態(tài)頁面的辦法與實現(xiàn)代碼詳細版
- 談PHP生成靜態(tài)頁面分析 模板+緩存+寫文件
- 方便實用的PHP生成靜態(tài)頁面類(非smarty)
- PHP批量生成靜態(tài)HTML的簡單原理和方法
相關(guān)文章
如何在symfony中導出為CSV文件中的數(shù)據(jù)
如果您需要在symfony中將數(shù)據(jù)庫中的數(shù)據(jù)導出為CSV文件,試試這個2011-10-10
PHP中simplexml_load_string函數(shù)使用說明
這個問題遇到好幾次了,今天翻看以前代碼的時候看到,便記下來,需要的朋友可以參考下。2011-01-01
在WordPress中實現(xiàn)發(fā)送http請求的相關(guān)函數(shù)解析
這篇文章主要介紹了在WordPress中實現(xiàn)發(fā)送http請求的相關(guān)函數(shù)解析,包括使用WP_Http類中的函數(shù)來發(fā)送post或get請求的方法,需要的朋友可以參考下2015-12-12
Laravel模板引擎Blade中section的一些標簽的區(qū)別介紹
這篇文章主要介紹了Laravel模板引擎Blade中section的一些標簽的區(qū)別介紹,本文講解了@yield 與 @section、@show 與 @stop、@append 和 @override的區(qū)別,需要的朋友可以參考下2015-02-02
php中__destruct與register_shutdown_function執(zhí)行的先后順序問題
這篇文章主要介紹了php中__destruct與register_shutdown_function執(zhí)行的先后順序問題,需要的朋友可以參考下2014-10-10

