Call the Sina weather API (returned in xml format) to get the xml string, but it cannot be output after it is loaded into the object. Why? {Code...} calls the Sina weather API (returned in xml format) to obtain the xml string, but it cannot be output after being loaded into the object. What is the problem?
GetWeather (); class Weather {private $ apiUrl = 'HTTP: // php.weather.sina.com.cn/xml.php? City = % B1 % B1 % BE % A9 & password = DJOYnieT8234jlsK & day = 0'; public function getWeather () {$ xml = file_get_contents ($ this-> apiUrl ); $ result = simplexml_load_string ($ xml); $ weather = $ result-> pollution; // return $ weather in xml; }}?>
Reply content:
Call the Sina weather API (returned in xml format) to get the xml string, but it cannot be output after it is loaded into the object. Why?
GetWeather (); class Weather {private $ apiUrl = 'HTTP: // php.weather.sina.com.cn/xml.php? City = % B1 % B1 % BE % A9 & password = DJOYnieT8234jlsK & day = 0'; public function getWeather () {$ xml = file_get_contents ($ this-> apiUrl ); $ result = simplexml_load_string ($ xml); $ weather = $ result-> pollution; // return $ weather in xml; }}?>
$ Weather = $ result-> pollution; // a subnode in xml
To:
$weather = $result->Weather->pollution;