天气预报api

@Ta 2015-04-19 3673点击
http://miai.sinaapp.com/api/do.php?act=weather&city=北京&key=wdkj

以下是半成品源码:要用请自己修改:
 <?php
 
function get($url,$post='')
{
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(isset($post)){
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post); }
curl_setopt($ch,CURLOPT_TIMEOUT,120);//超时
 
$content=curl_exec($ch);
curl_close($ch);
return $content;

 
$city=urlencode($_GET['city']);
$f=get("http://f.10086.cn/weather/sch.do?code=".$city."&userId=-1&fr=info&tp=");
#echo htmlspecialchars($f);
preg_match("!【今天】
(.*)【!Usi",$f,$info);
#print_r($info);
echo $today=strip_tags(str_replace("
","\n\r",$info[1]));
 
preg_match("!【明天】
(.*)【后天】!Usi",$f,$info);
#print_r($info);
echo $tomorrow=strip_tags(str_replace("
","\n\r",$info[1]));

 weather.php
回复列表(9|隐藏机器人聊天)
添加新回复
回复需要登录