一個(gè)顯示天氣預(yù)報(bào)的程序
更新時(shí)間:2006年10月09日 00:00:00 作者:
剛開(kāi)始學(xué)PHP,先編寫(xiě)了一個(gè)程序,放在自己的主頁(yè)上,可以顯示天氣預(yù)報(bào),當(dāng)然還很不完善,希望大家給提意見(jià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>
本來(lái)獲取的語(yǔ)句只需要執(zhí)行一次,然后將獲取的數(shù)據(jù)和舊數(shù)據(jù)比較,是否是新的,如果是新的,替換掉舊數(shù)據(jù),否則,不替換。這是有規(guī)律可尋的,先判斷時(shí)間,一般比預(yù)報(bào)時(shí)間晚一個(gè)小時(shí)的話(huà),肯定可以獲取最新的預(yù)報(bào)數(shù)據(jù)了。不過(guò)現(xiàn)在我沒(méi)有考慮那么多,以后再說(shuō)吧!
<?
$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>
本來(lái)獲取的語(yǔ)句只需要執(zhí)行一次,然后將獲取的數(shù)據(jù)和舊數(shù)據(jù)比較,是否是新的,如果是新的,替換掉舊數(shù)據(jù),否則,不替換。這是有規(guī)律可尋的,先判斷時(shí)間,一般比預(yù)報(bào)時(shí)間晚一個(gè)小時(shí)的話(huà),肯定可以獲取最新的預(yù)報(bào)數(shù)據(jù)了。不過(guò)現(xiàn)在我沒(méi)有考慮那么多,以后再說(shuō)吧!
您可能感興趣的文章:
- wenserver獲取天氣預(yù)報(bào)數(shù)據(jù)實(shí)例分享
- android調(diào)用國(guó)家氣象局天氣預(yù)報(bào)接口json數(shù)據(jù)格式解釋
- PHP+AJAX無(wú)刷新實(shí)現(xiàn)返回天氣預(yù)報(bào)數(shù)據(jù)
- Python天氣預(yù)報(bào)采集器實(shí)現(xiàn)代碼(網(wǎng)頁(yè)爬蟲(chóng))
- php結(jié)合飛信 免費(fèi)天氣預(yù)報(bào)短信
- 利用中國(guó)天氣預(yù)報(bào)接口實(shí)現(xiàn)簡(jiǎn)單天氣預(yù)報(bào)
相關(guān)文章
用PHP來(lái)寫(xiě)記數(shù)器(詳細(xì)介紹)
利用一個(gè)文本文件實(shí)現(xiàn)多個(gè)頁(yè)的計(jì)數(shù)減少服務(wù)器的I/O占用率在需要紀(jì)錄的文件里,只需加入很少的幾行代碼2006-10-10php checkbox復(fù)選框值的獲取與checkbox默認(rèn)值輸出方法
php獲取 checkbox復(fù)選框值的方法,checkbox在php讀取值時(shí)要用數(shù)組形式哦,我們讀取這些值用php post獲取是以一個(gè)array形式哦。2010-05-05