Heim  >  Artikel  >  php教程  >  一个显示天气预报的程序

一个显示天气预报的程序

WBOY
WBOYOriginal
2016-06-13 12:43:08900Durchsuche

刚开始学PHP,先编写了一个程序,放在自己的主页上,可以显示天气预报,当然还很不完善,希望大家给提意见。程序如下:

$fcont=file("http://www.bjmb.gov.cn/today.asp");
$arr=array();
for($i=0;$i    $tmp=$fcont[$i];
    $tmp=ereg_replace("
"," ",$tmp);
    if(!strstr(strtolower($tmp),"img")){
        $tmp=trim(strip_tags($tmp));
    } else {
        $st=ereg_replace(">⌒        $stt=split("⌒",$st);
        foreach($stt as $key => $value){
            if(strstr($value,"img") ){
                $tmp=$value;
                $tmp=ereg_replace("src=","width=30 height=30 align=absmiddle src=",$tmp);
                if(strstr($tmp,"bt9.jpg") || strstr($tmp,"colline.gif")) $tmp="";
            }
        }
    }
    if(trim($tmp)!="" && trim($tmp)!=" ") $arr[]=$tmp;
}
$yb=array();
for($i=2;$i    $yb[]=$arr[$i];
}
?>



本来获取的语句只需要执行一次,然后将获取的数据和旧数据比较,是否是新的,如果是新的,替换掉旧数据,否则,不替换。这是有规律可寻的,先判断时间,一般比预报时间晚一个小时的话,肯定可以获取最新的预报数据了。不过现在我没有考虑那么多,以后再说吧!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:综合图片计数器Nächster Artikel:用PHP调用Oracle存储过程