连接到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=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);
}
}
}
以某种方式连接,但有时它返回错误: 致命错误:在xx行/xlications/XAMPP/xamppfiles/htdocs/testing/application/controllers/google_weather.php中的非对象上调用成员函数xpath()
我该如何解决这个问题? thx in advanced!