Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // парсер изображений и описания состояний
- $col = 1; // кол-во дней (до 10, увеличивается время выдачи)
- $data_file = 'http://weather.yandex.ru/static/cities.xml';
- $xml = simplexml_load_file($data_file);
- foreach ($xml->country as $key => $value) {
- foreach ($value->city as $key1 => $value1):
- $out = getWeather($value1["id"], $col);
- foreach ($out as $day):
- foreach ($day['weather'] as $weather):
- $types[(string)$weather['weather_type']] = (string)$weather['image']; // массив описаний состояния с изображением
- $images[(string)$weather['image']] = (string)$weather['weather_type']; // массив изображений с описанием состояния
- endforeach;
- endforeach;
- endforeach;
- }
- foreach($types as $type=>$img):
- ?><img src="http://yandex.st/weather/1.2.61/i/icons/48x48/<?php echo $img;?>.png" width="48" height="48" /> - <?php echo $type.'<br />';
- endforeach;
- echo '<br><hr><br>';
- foreach($images as $img=>$type):
- ?><img src="http://yandex.st/weather/1.2.61/i/icons/48x48/<?php echo $img;?>.png" width="48" height="48" /> - <?php echo $type.'<br />';
- endforeach;
- /*
- заполняем массив при помощи функции, первый параметр идентификатор города, другие параметры необязательны - в этом случае используется значения по умолчанию
- */
- function getWeather($city, $col = 10) {
- $data_file = 'http://export.yandex.ru/weather-ng/forecasts/'.$city.'.xml'; // загружаем файл прогноза погоды для выбранного города
- $xml = simplexml_load_file($data_file); // загружаем xml файл через simple_xml
- $out = array(); // массив вывода прогноза
- $counter = 0 ; // счетчик количества дней, для которых доступен прогноз
- if($xml->day):
- foreach($xml->day as $day):
- if($counter == $col) break;
- for ($i=0;$i<=3;$i++) {
- $out[$counter]['weather'][$i]['image'] = $day->day_part[$i]->{'image-v3'};
- $out[$counter]['weather'][$i]['weather_type'] = $day->day_part[$i]->weather_type;
- }
- $counter++ ;
- endforeach;
- endif;
- return $out ;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement