独立的线出来,如下引入try/catch块:
try {
$url = "http://www.google.com/ig/api?weather=Moskva&hl=en";
$temp1 = file_get_contents($url);
$temp2 = utf8_encode($temp1);
$xml = simplexml_load_string($temp2);
echo $xml->weather->current_conditions->temp_c->attributes()->data;
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
然后会发生什么?
更新
你的反应是由于你是从哪里来的IP地址....这是响应:
http://www.google.com/sorry/?continue=http://www.google.com/ig/api%3Fweather%3DMoskva%26hl%3Den
键入响应URL到浏览器中给出了这样的:
我们的系统从您的计算机网络检测到异常流量。 本页面将检查您是否确实在发送请求,而不是机器人。为什么发生这种情况?
IP地址:90.214.41.66时间:2012-01-06T21:35:24Z网址: http://www.google.com/ig/api?weather=Moskva&hl=en
在浏览器中输入URL并完成CAPTCHA - 应该将分类
厂对我来说没有任何错误....什么是日志?输出“2”,但可以打印整个'$ xml' – ManseUK 2012-01-06 21:05:44
当你开始注释行时会发生什么?当你调用文件获取URL上的内容时会发生什么?当您尝试调试此代码时会发生什么? – afuzzyllama 2012-01-06 21:06:07
一切正常,直到我回声$ xml-> weather-> current_conditions-> temp_c-> attributes() - > data; – bluewhile 2012-01-06 21:21:04