【发布时间】:2016-08-19 11:49:27
【问题描述】:
我的代码有点工作,但我没有得到我想要的输出,我实际上只是想要输出“Gentle Breeze”,但我得到的是“SimpleXMLElement Object ([0] => Gentle Breeze)”
这是我的代码:
<head>
<title>Open Weather API</title>
</head>
<body>
<?php
$url = "http://api.openweathermap.org/data/2.5/forecast/daily?q=London&mode=xml&units=metric&cnt=16&appid=Key";
$xml = simplexml_load_file($url);
foreach($xml->forecast->time as $times)
{
$windspeed[] = $times->windSpeed["name"];
}
print_r($windspeed[0])
?>
</body>
我尝试使用 echo 代替 print_r,但输出的都是“Array”
这是我从 API 中提取的 XML 示例:
<time day="2016-08-19">
<symbol number="500" name="light rain" var="10d"/>
<precipitation value="2.97" type="rain"/>
<windDirection deg="188" code="S" name="South"/>
<windSpeed mps="5.28" name="Gentle Breeze"/>
<temperature day="22.58" min="17.06" max="22.58" night="18.39" eve="18.61" morn="17.06"/>
<pressure unit="hPa" value="1012.32"/>
<humidity value="72" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
我需要将它存储在一个数组中,以便稍后在我的代码中调用它,我只是将结果作为测试输出,以查看存储在数组中的内容,我只是希望它存储“Gentle Breeze " 不是 "SimpleXMLElement 对象 ([0] => 微风)"
【问题讨论】:
-
看起来像多维数组,试试
echo $windspeed[0][0] -
我试过了,好像没用
标签: php html xml simplexml openweathermap