这个地址:http://maps.google.com/ig/api?weather=shanghai&hl=zh-cn
是google返回的一个天气预报xml
想调用到本地来:<?php
readfile('http://maps.google.com/ig/api?weather=shanghai&hl=zh-cn');
?>
提示错误:无法显示 XML 页。
使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost/Flash_Weather/weather_google.php' 时出错。第 1 行,位置: 438 <?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zippe...
是怎么回事呢?谢谢了..
是google返回的一个天气预报xml
想调用到本地来:<?php
readfile('http://maps.google.com/ig/api?weather=shanghai&hl=zh-cn');
?>
提示错误:无法显示 XML 页。
使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost/Flash_Weather/weather_google.php' 时出错。第 1 行,位置: 438 <?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zippe...
是怎么回事呢?谢谢了..
$data = file_get_contents('http://maps.google.com/ig/api?weather=shanghai&hl=zh-cn');
$parser = xml_parser_create();
xml_parse_into_struct($parser, $data, $values, $index);
xml_parser_free($parser);
var_dump($values);
?>
echo file_get_contents('http://maps.google.com/ig/api?weather=shanghai&hl=zh-cn');
鬼知道咋回事,
他的编码有问题.
只能用gbk的头.
返回的明明是utf-8,但其实非得自己声明成gbk才成,非常奇怪.(Status-Line) HTTP/1.1 200 OK
Content-Type text/xml; charset=UTF-8
Date Fri, 16 Apr 2010 02:25:55 GMT
Pragma no-cache
Expires Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control no-cache, no-store, must-revalidate
X-Content-Type-Options nosniff
Content-Encoding gzip
Server igfe
Content-Length 519
[0] => HTTP/1.0 200 OK [1] => Content-Type: text/xml; charset=GB2312 [2] => Date: Fri, 16 Apr 2010 06:49:52 GMT [3] => Pragma: no-cache [4] => Expires: Fri, 01 Jan 1990 00:00:00 GMT [5] => Cache-Control: no-cache, no-store, must-revalidate [6] => Set-Cookie: PREF=ID=a4b2c4647e53a911:NW=1:TM=1271400592:LM=1271400592:S=Nycu6vbm14iJGexY; expires=Sun, 15-Apr-2012 06:49:52 GMT; path=/; domain=.google.com [7] => X-Content-Type-Options: nosniff [8] => Server: igfe
直接读出来的内容写入xml但是认不出来中文,确实要设置一下头,奇怪
其实这个很好 http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">
<string>直辖市 上海</string>
<string>上海</string>
<string>2013</string>
<string>2010/04/16 14:47:40</string>
<string>今日天气实况:气温:15.4℃;风向/风力:东北风 小于3级;湿度:40%;气压:1023.4hPa</string>
<string>空气质量:良;紫外线强度:中等</string>
<string>穿衣指数:建议着薄型套装或牛仔衫裤等春秋过渡装。年老体弱者宜着套装、夹克衫等。感冒指数:天气较凉,较易发生感冒,请适当增加衣服。体质较弱的朋友尤其应该注意防护。晨练指数:早晨气象条件较适宜晨练,但风力稍大,晨练时会感觉有点凉,晨练时着装不要过于单薄,选择避风的地点。洗车指数:较不宜洗车,未来一天无雨,风力较大,如果执意擦洗汽车,要做好蒙上污垢的心理准备。晾晒指数:天气晴朗,午后温暖的阳光仍能满足你驱潮消霉杀菌的晾晒需求。旅游指数:天气晴朗,风稍大,但温度适宜,是个好天气哦。很适宜旅游,您可以尽情地享受大自然的无限风光。路况指数:晴天,其它条件适宜,路面比较干燥,路况较好。舒适度指数:白天不太热也不太冷,风力不大,相信您在这样的天气条件下,应会感到比较清爽和舒适。</string>
<string>4月16日 晴</string>
<string>9℃/15℃</string>
<string>东南风3-4级</string>
<string>0.gif</string>
<string>0.gif</string>
<string>4月17日 晴转多云</string>
<string>13℃/19℃</string>
<string>南风4-5级</string>
<string>0.gif</string>
<string>1.gif</string>
<string>4月18日 阵雨</string>
<string>14℃/19℃</string>
<string>南风4-5级</string>
<string>3.gif</string>
<string>3.gif</string>
<string>4月19日 阵雨</string>
<string>15℃/19℃</string>
<string>南风3-4级转4-5级</string>
<string>3.gif</string>
<string>3.gif</string>
<string>4月20日 阵雨</string>
<string>16℃/20℃</string>
<string>南风4-5级转东南风4-5级</string>
<string>3.gif</string>
<string>3.gif</string>
</ArrayOfString>
我是想把xml传到本地来,方便flash调用xml文件,因为flash无法跨域.
没有其他办法能传回完整页面了吗?
我是ff httpfox读取的
高手..会不会是这里的 换码字符 问题?
$data = file_get_contents('http://maps.google.com/ig/api?weather=shanghai&hl=zh-cn');
$parser = xml_parser_create();
xml_parse_into_struct($parser, $data, $values, $index);
xml_parser_free($parser);
var_dump($values);
?>
这样返回的无法显示中文,最好能直接输出xml的..这样方便很多..
//我用以下代碼可以正常讀及寫http://maps.google.com/ig/api?weather=guangzhou&hl=zh-cn$content = file_get_contents('http://maps.google.com/ig/api?weather=guangzhou&hl=zh-cn');
//header("Content-type:text/xml;charset=GBK");
//echo $content;
if($fp = fopen('weather.xml','w+')){
fwrite($fp,$content);
fclose($fp);
}