Answer the question
In order to leave comments, you need to log in
How to parse xml yandex weather?
Hello. Actually, I can not parse the weather from Yandex. Here is the code but it doesn't work. Fix what's wrong with him. I will be very grateful.
<?php
$city_id=10646; // id города
$data_file="https://export.yandex.ru/bar/reginfo.xml/$city_id.xml"; // адрес xml файла
$xml = simplexml_load_file($data_file); // раскладываем xml на массив
// выбираем требуемые параметры (город, температура, пиктограмма и тип погоды текстом (облачно, ясно)
$city=$xml->fact->city;
$temp=$xml->fact->temperature;
$pic=$xml->fact->image-v3;
$type=$xml->fact->weather_type;
// Если значение температуры положительно, для наглядности добавляем "+"
if ($temp>0) {$temp='+'.$temp;}
?>
<div id="weather">
<?php
echo ("<a href=\"https://yandex.ru/pogoda/gubkin/\">$city</a>");
echo ("<img src=\"https://yastatic.net/weather/i/icons/blueye/48/skc_$pic.png\" alt=\"$type\" title=\"$type\">$temp<sup>o</sup>C");
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question