我正在尝试读取元素名称中包含“-”的 xml feed。可以在此处找到源。
我是 php 新手,所以我可能会忽略一些基本的东西。我正在使用 SimpleXML 来读取提要。这是我用来解决我的问题的一些基本代码。我阅读了预测和最低温度,没有任何问题。当我尝试读取条件图标时,php 不起作用(这是我在底部注释掉的部分)
<?php
$feed_url = 'http://forecast.weather.gov/MapClick.php?lat=42.19774&lon=-121.81797&FcstType=dwml';
$ch = curl_init($feed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
if (!empty($result))
{
$xml = new SimpleXMLElement($result);
print "<br> Discription\n";
$wordedForecast = $xml->data->parameters->wordedForecast->text;
foreach ($wordedForecast as $value)
{
print "<br> $value\n";
}
print "<br> Min Tempature\n";
$Tempature = $xml->data->parameters->temperature->value;
foreach ($Tempature as $value)
{
print "<br> $value\n";
}
print"<br>conditions Icon link\n";
//This is one of the elements that I am stumped on how to read.
/* $conditions= $xml->data->parameters->conditions-icon->icon-link;
foreach ($conditions as $value)
{
print "<br> $value\n";
}
*/
}
?>
我确信这个问题的答案很简单,但我已经没有关于如何解决这个问题的想法了。我也有同样的问题<time-layout>
,<probability-of-precipitation>
, and <weather-conditions>
元素。
感谢您提供有关如何使其发挥作用的任何答案或想法。
try $xml->data->parameters->{'conditions-icon'}->{'icon-link'}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)