获取上海天气预报

[code]
//php
$u1=”http://www.weather.com.cn/data/sk/101020100.html”;
$u2=”http://www.weather.com.cn/data/cityinfo/101020100.html”;
$r1=file_get_contents($u1);
$r2=file_get_contents($u2);

$a1=explode(“,”,$r1);
$a2=explode(“,”,$r2);

function handle($r1)
{
$r= Json_decode($r1);
//print_r($r);
$temp = $r->weatherinfo->temp;
$wind = $r->weatherinfo->WD;
$level = $r->weatherinfo->WS;
$sd=$r->weatherinfo->SD;
$st = “温度:”.$temp.”,湿度:”.$sd.”,”.$wind.$level;
return $st;
}

function handle2($r1)
{
$r= Json_decode($r1);
//print_r($r);
$temp = $r->weatherinfo->weather;
return $temp;
}

$mailsubject = handle($r1).”,”.handle2($r2);
[/code]

若要获取其他城市天气,参考下面文章
http://g.kehou.com/t1029846752.html
http://www.cnblogs.com/TianFang/archive/2013/01/03/2842913.html

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>