1

连接到 google 天气 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 行的 /Applications/XAMPP/xamppfiles/htdocs/testing/application/controllers/google_weather.php 中的非对象上调用成员函数 xpath()

我该如何解决这个问题?thx 先进!

4

0 回答 0