生成静态函数
时间:2006-08-02 来源:yanjing5462
function php2html ($url='http://localhost', $htmlFilePath='/tmp/', $htmlFileName='index.html', $logPath='/tmp/', $logName='log.txt')
{
$htmlContent = file_get_contents($url); //将文件读入 $f_index_html 变量
$htmlPathFile = $htmlFilePath . $htmlFileName; //要生成文件及路径 例: "a/index.html"
//die($htmlPathFile);
if (is_file($htmlPathFile))
{
@unlink($htmlPathFile);//若文件已存在,则删除
}
$handle = fopen ($htmlPathFile, "w"); //打开文件指针,创建文件
if (!is_writable ($htmlPathFile))
{
$Msg = "文件:" . $htmlPathFile . "不可写,请检查其属性后重试\r\n";
}
else if (!fwrite ($handle, $htmlContent))
{ //将信息写入文件
$Msg = "生成文件" . $htmlPathFile . "失败\r\n";
}
else
{
$Msg = "创建文件" . $htmlPathFile . "成功\r\n";
}
$msgPrefix = date("Y-m-d H:i:s");
$logMsg = '(' . $msgPrefix . ')' . $Msg;
$logHandle = fopen ($logPath . $logName, "a+"); //打开日志文件
fwrite ($logHandle, $logMsg);
fclose($logHandle);
fclose ($handle); //关闭指针
}
php2html("
http://www.pmec.net
", "/home/yanjing/public_html/yanjing/html/", "index.html", dirname(__FILE__)."/log/", "log.txt");
?>
相关阅读 更多 +
排行榜 更多 +