php2html php生成靜態(tài)頁函數(shù)
更新時間:2008年12月08日 00:34:50 作者:
生成靜態(tài)函數(shù) 這里要用到的路徑為服務(wù)器絕對路徑; 若給定的路徑目錄不存在則自動創(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ù)器絕對路徑; 若給定的路徑目錄不存在則自動創(chuàng)建
=======================================================================================
@ Example:php2html("http://chabaoo.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)頁部分
*/
$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://chabaoo.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ù)器絕對路徑; 若給定的路徑目錄不存在則自動創(chuàng)建
=======================================================================================
@ Example:php2html("http://chabaoo.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)頁部分
*/
$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://chabaoo.cn", 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)文件的方法緩解服務(wù)器壓力
- 解析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)文章
PHP查詢MySQL大量數(shù)據(jù)的時候內(nèi)存占用分析
這篇文章主要是從原理, 手冊和源碼分析在PHP中查詢MySQL返回大量結(jié)果時, 內(nèi)存占用的問題, 同時對使用MySQL C API也有涉及.2011-07-07PHPCrawl爬蟲庫實現(xiàn)抓取酷狗歌單的方法示例
這篇文章主要介紹了PHPCrawl爬蟲庫實現(xiàn)抓取酷狗歌單的方法,涉及PHPCrawl爬蟲庫的使用及正則匹配相關(guān)操作技巧,需要的朋友可以參考下2017-12-12php使用array_search函數(shù)實現(xiàn)數(shù)組查找的方法
這篇文章主要介紹了php使用array_search函數(shù)實現(xiàn)數(shù)組查找的方法,涉及php數(shù)組查找的相關(guān)技巧,需要的朋友可以參考下2015-06-06通過PHP的內(nèi)置函數(shù),通過DES算法對數(shù)據(jù)加密和解密
數(shù)據(jù)加密的基本過程就是對原來為明文的文件或數(shù)據(jù)按某種算法進行處理,使其成為不可讀的一段代碼,通常稱為密文,使其只能在輸入相應(yīng)的密鑰之后才能顯示出本來內(nèi)容,通過這樣的途徑來達到保護數(shù)據(jù)不被非法人竊取、閱讀的目的2012-06-06