小子的博客

宝剑锋从磨砺出,梅花香自苦寒来。

2592763179.jpg

1.上传文件夹到插件目录
2.到后台激活插件
3.由于emlog4.0机制问题,需要手动修改模版
修改当前正在使用的模版的log_list.php文件,找到

1
<?php doAction('index_loglist_top'); ?>
在下面添加
1
<?php $logs = getLogThumb(); ?>

已修正路径:点我下载(logthumb.zip)


网上搜到通过传入地区的拼音可以获取当地的天气,于是想通过IP查到的地址转为拼音后获取天气,今天试了一下,直接通过汉字也可以查询,返回xml格式,这样就免了转换拼音的步骤

1
http://www.google.com/ig/api?weather=Beijing

1
http://www.google.com/ig/api?weather=北京

这样,通过咱上上篇文章,可以获取到近三天的天气了。


结合上篇文章,就可以根据IP显示天气啦

1
2
3
4
5
6
$headers = array('Referer:http://cgi.web2.qq.com/proxy.html');
$handle = curl_init('http://cgi.web2.qq.com/cgi/qqweb/weather/wth/weather.do?retype=1');
//city=%E8%8B%8F%E5%B7%9E
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_exec($handle);
curl_close($handle);

返回的是json格式:

1
{"now_temperature":"18","update_time":"12:19","now_pic":"b_a1.png","city":"苏州"}

PS:这种方法只能显示当前实时天气


此处不多说,仅写关于取值方面的代码。

丶2011/4/24 更新: 县级市的匹配

1
2
3
4
5
6
7
8
9
10
$content = $this->fetch('http://ip.qq.com/cgi-bin/searchip?searchip1=121.236.225.37');
preg_match('/该IP所在地为:<span>(.*?)<\/span>/i', $content, $match);
$result = array();
list($address, $isp) = explode('&nbsp;&nbsp;&nbsp;', $match[1]);
preg_match('/(.*国)?(.*省)?(.*市)?(.*[市县区])?/i', $address, $info);
$result['country'] = $info[1];
$result['province'] = $info[2];
$result['city'] = $info[3];
$result['district'] = $info[4];
$result['isp'] = $isp;

以上代码要注意编码的一些问题。
PS: http://fw.qq.com/ipaddress 使用php是获取不到查询结果的,获取到的都是服务器的IP,网上没经过测试就转载的很多,以讹传讹,注意辨别!