這次改進,主要是增加了圖象的獲取,並提供了一個比較完整的獲取遠端文件的函數。具體代碼如下:
<?
$fcont=file("http://www.bjmb.gov.cn/today.asp");
$arr=array();
for($i=0;$i<count($fcont);$i++){
$tmp=$fcont[$i];
$tmp=ereg_replace("<br>"," ",$tmp);
if(!strstr(strtolower($tmp),"img")){
$tmp=trim(strip_tags($tmp));
} else {
$st=ereg_replace("><",">⌒<",$tmp);
$stt=split("⌒",$st);
foreach($stt as $key => $value){
if(strstr($value,"img") ){
$tmp=$value;
if(strstr($tmp,"bt9.jpg") || strstr($tmp,"colline.gif")){
$tmp="";
}else{
$tmp=ereg_replace(""","",$tmp);
$st=split("src=",$tmp);
$st1=split(" ",$st[1]);getpic("http://www.bjmb.gov.cn/$st1[0]","image");
if(count($st)>2){
$st2=split(" ",$st[2]);getpic("http://www.bjmb.gov.cn/$st1[0]","image");
}