php2html php生成靜態(tài)頁(yè)函數(shù)
更新時(shí)間:2008年12月08日 00:34:50 作者:
生成靜態(tài)函數(shù) 這里要用到的路徑為服務(wù)器絕對(duì)路徑; 若給定的路徑目錄不存在則自動(dòng)創(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
@ 提示:這里要用到的路徑為服務(wù)器絕對(duì)路徑; 若給定的路徑目錄不存在則自動(dòng)創(chuàng)建
=======================================================================================
@ Example:php2html("http://www.dbjr.com.cn", "/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)頁(yè)部分
*/
$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"); //打開(kāi)文件指針,創(chuàng)建文件
$logHandle = fopen ($out_logFile, "a+"); //打開(kāi)日志文件
/**
* @檢查目錄是否可寫(xiě)
*/
if (!is_writable($out_htmlFile))
{
echo "文件:".$out_htmlFile."不可寫(xiě),請(qǐng)檢查目錄屬性后重試";
exit();
}
if (!is_writable($out_logFile))
{
echo "文件:".$out_logFile."不可寫(xiě),請(qǐng)檢查目錄屬性后重試";
exit();
}
/**
* @寫(xiě)入文件
*/
if (!fwrite ($handle, $htmlContent))
{
$logMsg = "寫(xiě)入文件" . $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.dbjr.com.cn", 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
@ 提示:這里要用到的路徑為服務(wù)器絕對(duì)路徑; 若給定的路徑目錄不存在則自動(dòng)創(chuàng)建
=======================================================================================
@ Example:php2html("http://www.dbjr.com.cn", "/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)頁(yè)部分
*/
$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"); //打開(kāi)文件指針,創(chuàng)建文件
$logHandle = fopen ($out_logFile, "a+"); //打開(kāi)日志文件
/**
* @檢查目錄是否可寫(xiě)
*/
if (!is_writable($out_htmlFile))
{
echo "文件:".$out_htmlFile."不可寫(xiě),請(qǐng)檢查目錄屬性后重試";
exit();
}
if (!is_writable($out_logFile))
{
echo "文件:".$out_logFile."不可寫(xiě),請(qǐng)檢查目錄屬性后重試";
exit();
}
/**
* @寫(xiě)入文件
*/
if (!fwrite ($handle, $htmlContent))
{
$logMsg = "寫(xiě)入文件" . $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.dbjr.com.cn", dirname(__FILE__)."/yanjing_html/index.html", dirname(__FILE__)."/yanjing_log/log.txt");
echo "成功";
?>
您可能感興趣的文章:
- PHP中批量生成靜態(tài)html(命令行下運(yùn)行PHP)
- php生成靜態(tài)頁(yè)面的簡(jiǎn)單示例
- PHP 動(dòng)態(tài)生成靜態(tài)HTML頁(yè)面示例代碼
- PHP中實(shí)現(xiàn)生成靜態(tài)文件的方法緩解服務(wù)器壓力
- 解析PHP生成靜態(tài)html文件的三種方法
- 基于PHP生成靜態(tài)頁(yè)的實(shí)現(xiàn)方法
- php添加文章時(shí)生成靜態(tài)HTML文章的實(shí)現(xiàn)代碼
- 利用PHP生成靜態(tài)HTML文檔的原理
- php生成靜態(tài)文件的多種方法分享
- 比較詳細(xì)PHP生成靜態(tài)頁(yè)面教程
- 用php的ob_start來(lái)生成靜態(tài)頁(yè)面的方法分析
- PHP定時(shí)自動(dòng)生成靜態(tài)HTML的實(shí)現(xiàn)代碼
- php將數(shù)據(jù)庫(kù)中所有內(nèi)容生成靜態(tài)html文檔的代碼
- 通用PHP動(dòng)態(tài)生成靜態(tài)HTML網(wǎng)頁(yè)的代碼
- php 生成靜態(tài)頁(yè)面的辦法與實(shí)現(xiàn)代碼詳細(xì)版
- 談PHP生成靜態(tài)頁(yè)面分析 模板+緩存+寫(xiě)文件
- 方便實(shí)用的PHP生成靜態(tài)頁(yè)面類(lèi)(非smarty)
- PHP批量生成靜態(tài)HTML的簡(jiǎn)單原理和方法
相關(guān)文章
php文件后綴不強(qiáng)制為.php的實(shí)操方法
在本篇文章里小編給大家整理的是一篇關(guān)于php文件后綴不強(qiáng)制為.php的實(shí)操方法,有需要的朋友們參考下。2019-09-09PHP獲取當(dāng)前頁(yè)面URL函數(shù)實(shí)例
這篇文章主要介紹了PHP獲取當(dāng)前頁(yè)面URL函數(shù)實(shí)例,講述了一個(gè)非常簡(jiǎn)單實(shí)用的獲取當(dāng)前頁(yè)面URL的函數(shù),并附帶說(shuō)明了server參數(shù)的用法,需要的朋友可以參考下2014-10-10PHP查詢MySQL大量數(shù)據(jù)的時(shí)候內(nèi)存占用分析
這篇文章主要是從原理, 手冊(cè)和源碼分析在PHP中查詢MySQL返回大量結(jié)果時(shí), 內(nèi)存占用的問(wèn)題, 同時(shí)對(duì)使用MySQL C API也有涉及.2011-07-07PHPCrawl爬蟲(chóng)庫(kù)實(shí)現(xiàn)抓取酷狗歌單的方法示例
這篇文章主要介紹了PHPCrawl爬蟲(chóng)庫(kù)實(shí)現(xiàn)抓取酷狗歌單的方法,涉及PHPCrawl爬蟲(chóng)庫(kù)的使用及正則匹配相關(guān)操作技巧,需要的朋友可以參考下2017-12-12php使用array_search函數(shù)實(shí)現(xiàn)數(shù)組查找的方法
這篇文章主要介紹了php使用array_search函數(shù)實(shí)現(xiàn)數(shù)組查找的方法,涉及php數(shù)組查找的相關(guān)技巧,需要的朋友可以參考下2015-06-06通過(guò)PHP的內(nèi)置函數(shù),通過(guò)DES算法對(duì)數(shù)據(jù)加密和解密
數(shù)據(jù)加密的基本過(guò)程就是對(duì)原來(lái)為明文的文件或數(shù)據(jù)按某種算法進(jìn)行處理,使其成為不可讀的一段代碼,通常稱(chēng)為密文,使其只能在輸入相應(yīng)的密鑰之后才能顯示出本來(lái)內(nèi)容,通過(guò)這樣的途徑來(lái)達(dá)到保護(hù)數(shù)據(jù)不被非法人竊取、閱讀的目的2012-06-06