我有一个创建simplexml_load_file();
$xmlPoland = simplexml_load_file('http://export.yandex.ru/weather-ng/forecasts/12375.xml');
echo "<pre>";
print_r($xmlPoland);
echo "</pre>";
我需要获取[fact] temperature
(-9
)的值。
如何制作?
答案 0 :(得分:0)
这应该适合你:
echo $xmlPoland->fact->temperature;
输出:
-9
如果你需要这部分:
[fact] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source] => forecast
)
[observation_time] => 2014-12-29T19:06:19
[uptime] => 2014-12-29T19:06:19
[temperature] => -9
[weather_condition] => SimpleXMLElement Object
(
[@attributes] => Array
(
[code] => mostly-clear
)
)
我也建议你看看这里:http://php.net/manual/en/function.simplexml-load-file.php
正如@superultranova建议的那样:http://php.net/manual/en/book.simplexml.php