xml错误:对非对象调用成员函数xpath()
我在连接到google weather api时出错xml错误:对非对象调用成员函数xpath(),xml,api,codeigniter,weather,Xml,Api,Codeigniter,Weather,我在连接到google weather api时出错 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Google_weather extends CI_Controller { function index() { $xml = simplexml_load_file('http://www.google.com/ig/api?weather=cali
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Google_weather extends CI_Controller {
function index()
{
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=california');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
$pic = $current[0]->icon['data'];
if($pic == "/ig/images/weather/chance_of_snow.gif") { $changeImage = base_url()."images/web/chance-of-snow.png"; }
else if($pic == "/ig/images/weather/flurries.gif") { $changeImage = base_url()."images/web/flurries.png"; }
else if($pic == "/ig/images/weather/snow.gif") { $changeImage = base_url()."images/web/snow.png"; }
else if($pic == "/ig/images/weather/sleet.gif") { $changeImage = base_url()."images/web/sleet.png"; }
else if($pic == "/ig/images/weather/chance_of_rain.gif") { $changeImage = base_url()."images/web/chance-of-rain.png"; }
else if($pic == "/ig/images/weather/chance_of_storm.gif") { $changeImage = base_url()."images/web/chance-of-storm.png"; }
$data = array('weather' => $changeImage);
$this->load->view('weather_view.php',$data);
}
}
你说有时是什么意思?代码看起来正常,但错误意味着$xml设置不正确。当它返回一个错误时,与它工作时相比,你能确定是否有什么不同吗?