一個顯示天氣預(yù)報(bào)的程序
更新時間:2006年10月09日 00:00:00 作者:
剛開始學(xué)PHP,先編寫了一個程序,放在自己的主頁上,可以顯示天氣預(yù)報(bào),當(dāng)然還很不完善,希望大家給提意見。程序如下:
<?
$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;
$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<count($arr)-6;$i++){
$yb[]=$arr[$i];
}
?>
<br>
<SCRIPT LANGUAGE="JavaScript">
<!--
syb="";
<?
$exp="-3-7-9-14-18-20-25-";
for ($i=1;$i<count($yb);$i++){
if (!strstr($exp,"-".(string)($i+1)."-")){
?>
syb=syb+'<?=$yb[$i];?> ';
<?}}?>
document.write("<?=$yb[0]?>"+":");
document.write("<marquee width=400 align=middle scrollamount=5 scrolldelay=200>"+syb+"預(yù)報(bào)</marquee>");
//-->
</SCRIPT>
本來獲取的語句只需要執(zhí)行一次,然后將獲取的數(shù)據(jù)和舊數(shù)據(jù)比較,是否是新的,如果是新的,替換掉舊數(shù)據(jù),否則,不替換。這是有規(guī)律可尋的,先判斷時間,一般比預(yù)報(bào)時間晚一個小時的話,肯定可以獲取最新的預(yù)報(bào)數(shù)據(jù)了。不過現(xiàn)在我沒有考慮那么多,以后再說吧!
<?
$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;
$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<count($arr)-6;$i++){
$yb[]=$arr[$i];
}
?>
<br>
<SCRIPT LANGUAGE="JavaScript">
<!--
syb="";
<?
$exp="-3-7-9-14-18-20-25-";
for ($i=1;$i<count($yb);$i++){
if (!strstr($exp,"-".(string)($i+1)."-")){
?>
syb=syb+'<?=$yb[$i];?> ';
<?}}?>
document.write("<?=$yb[0]?>"+":");
document.write("<marquee width=400 align=middle scrollamount=5 scrolldelay=200>"+syb+"預(yù)報(bào)</marquee>");
//-->
</SCRIPT>
本來獲取的語句只需要執(zhí)行一次,然后將獲取的數(shù)據(jù)和舊數(shù)據(jù)比較,是否是新的,如果是新的,替換掉舊數(shù)據(jù),否則,不替換。這是有規(guī)律可尋的,先判斷時間,一般比預(yù)報(bào)時間晚一個小時的話,肯定可以獲取最新的預(yù)報(bào)數(shù)據(jù)了。不過現(xiàn)在我沒有考慮那么多,以后再說吧!
相關(guān)文章
php checkbox復(fù)選框值的獲取與checkbox默認(rèn)值輸出方法
php獲取 checkbox復(fù)選框值的方法,checkbox在php讀取值時要用數(shù)組形式哦,我們讀取這些值用php post獲取是以一個array形式哦。2010-05-05