微信开发天气预报教程默认城市是郑州
需要注意的是:
1:weatherdata.txt是反序列化的城市天气网址,所以需要反序列化。
2: $contentStr = "$contentStrReturn";$contentStr赋值号后面的必须加引号,不加不正常显示。
下面贴出来天气预报代码和需要用到的文件
function getweather($city = '北京', $data = 'weatherdata.txt') // 获取天气预报内容
{
$urlarr = unserialize ( file_get_contents ( $data ) );
if (isset($urlarr [$city])) {
$url = $urlarr [$city];
$text = $city;
$lines_string = file_get_contents ( $url );
$lines_string = explode ( "<title>", $lines_string );
$lines_string_start = explode("</title>",$lines_string[1]);
return $lines_string_start[0];
}
}
// $keyword = '郑州';
$contentStrReturn = getweather($keyword, 'weatherdata.txt');
$contentStr = "$contentStrReturn";
http://pan.baidu.com/s/1kni94