Парсинг xml в php
Пытаюсь спарсить xml, но походу как-то не так дела, подскажите, пожалуйста Вот так выглядит xml файл (его часть)
<weatherdata>
<forecast>
<tabular>
<time from="2020-04-18T20:00:00" to="2020-04-19T00:00:00" period="3">
<symbol number="3" numberEx="3" name="Partly cloudy" var="03d"/>
<precipitation value="0"/>
<windDirection deg="297.8" code="WNW" name="West-northwest"/>
<windSpeed mps="5.5" name="Moderate breeze"/>
<temperature unit="celsius" value="5"/>
<pressure unit="hPa" value="1014.7"/>
</time>
<time from="2020-04-19T00:00:00" to="2020-04-19T06:00:00" period="0">
<symbol number="3" numberEx="3" name="Partly cloudy" var="03n"/>
<precipitation value="0"/>
<windDirection deg="280.1" code="W" name="West"/>
<windSpeed mps="3.4" name="Gentle breeze"/>
<temperature unit="celsius" value="1"/>
<pressure unit="hPa" value="1013.9"/>
</time>
...
</weatherdata>
Я хочу вытянуть из этих классов time значения (а точнее, я хочу вытянуть именно те значения, в которых моя переменная совпадает с временем в xml), но у меня считываются значения только с первой части класса (или как это правильно называется) Прилагаю свой код (точнее часть кода, где я пытаюсь это сделать) Можно я ошиблась где-то в синтаксисе, подскажите, пожалуйста!!) Код:
$src = file_get_contents('https://www.yr.no/place/'. $_GET['city'] .'/forecast.xml');
$data = new SimpleXMLElement($src);
$str = $data->forecast->tabular->time;
foreach ($data as $str) {
if(strtotime($str["from"]) >= strtotime($_GET['date']) && strtotime($_GET['date']) <= strtotime($str['to'])){
$forecast["Temperature:"] = (string) $str->temperature["value"];
$forecast["Precipitation:"] = (string) $str->precipitation["value"];
$windDirection = $str->windDirection["name"];
$forecast["Wind:"] = (string) $str->windSpeed["mps"] . " m/s from $windDirection";
$date = date ("d.m.y H:i", strtotime($_GET['date']));
$city = $data->location->name;
$result = "OK";
//break;
}
else {
$result = "ERROR";
$error_message = "Not found";
}
}