免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 925 | 回复: 0
打印 上一主题 下一主题

天气预报 数据获取 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-21 12:50 |只看该作者 |倒序浏览

?php
/**
* 天气日报 数据获取
* 编码:gb2312
* 建议写成 cache 使用
* 希望大家能帮我把代码写得更好一点
*
* @author 潘春孟
* @version 0.00 2006.11.21
* @param int $id
* @return Array weather
*/
function weather($id=59431){
    $from= str_replace("\n",'',file_get_contents("http://www.weathercn.com/forecast/24time.jsp?sta_id=$id"));
   
    preg_match_all("/(.*?)/",$from,$element);
   
    $element[0][10]=str_replace('','',$element[0][10]);
    $element[0][10]=str_replace('','',$element[0][10]);
    $element[0][10]=str_replace(',',$element[0][10]);
   
    if(strspn('.gif',$element[0][11])){
        $pic2=1;
        $element[0][11]=str_replace('','',$element[0][11]);
     $element[0][11]=str_replace('','',$element[0][11]);
     $element[0][11]=str_replace(',',$element[0][11]);
     $pic2Eliment=$element[0][11];
    }
    else{
        $pic2=0;
        $pic2Eliment='';
    }
   
    $weather=array(
     '时间' => trim(strip_tags($element[0][9])),
     '天气云图' => trim($element[0][10]),
     '天气云图2' => trim($pic2Eliment),
     '气温' => trim(strip_tags($element[0][11+$pic2])),
     '风讯' => trim(strip_tags($element[0][12+$pic2])),
     '天气描述' => trim(strip_tags($element[0][25+$pic2])),
     '地理描述' => trim(strip_tags($element[0][28+$pic2])),
     );
     
    $element028=explode('|',strip_tags($element[0][28+$pic2]));
   
    $weather['日出']=trim($element028[0]);
    $weather['日落']=trim($element028[1]);
    $weather['东经']=trim($element028[2]);
    $weather['北纬']=trim($element028[3]);
    $weather['海拔']=trim($element028[4]);
   
    //print_r($weather);
    return $weather;
}
print_r(Weather(45011));
?>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/17173/showart_204158.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP