Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $city_id = 27612; // id Москвы
- $xml = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'weather_'.$city_id.'.xml';
- if(file_exists($xml)):
- $data = simplexml_load_file($xml); //грузим ?>
- <style type="text/css">
- .weather{position:relative;border-bottom:1px solid #d5d5d5;padding-bottom:35px;}
- .weather .date{font-size:13px;font-weight:700;padding-bottom:5px;text-transform:uppercase;border-bottom:1px solid #d5d5d5;margin-top:10px;}
- .weather .item{background-color:#f0eedc;padding:15px;font-family:Georgia;margin-bottom:20px;}
- .weather .item table{border:0;width:100%;}
- .weather .item table td{padding-bottom:15px;width:20%;vertical-align:baseline;padding-right:5px;}
- .weather .item .day-part td{font-size:18px;}
- .weather .item .day-temp td{font-size:30px;}
- .weather .item .day-temp td img{margin-left:5px;}
- .weather .item .day-param td{font-size:12px;}
- .weather .item .day-param td p{padding-bottom:3px;}
- .weather .days{margin-top:35px;border:0;width:100%;}
- .weather .days td{width:50%;padding-bottom:35px;}
- .weather .days a{font-family:Georgia;font-size:18px;text-decoration:underline;font-weight:700;}
- </style>
- <div class="weather"><?php
- foreach($data->day as $day):?>
- <div class="date"><?php echo getDayDate($day['date']);?></div>
- <div class="item">
- <table>
- <tr class="day-part">
- <td>Утром</td>
- <td>Днем</td>
- <td>Вечером</td>
- <td>Ночью</td>
- </tr>
- <tr class="day-temp">
- <?php for($i = 0;$i < 4;$i++): // т.к. нам не нужны данные day_short и night_short, мы останавливаем проход на 4
- $img = $day->day_part[$i]->{'image-v3'};?>
- <td><?php echo getTempSign($day->day_part[$i]->{'temperature-data'}->avg);?> °C <img src="<?php echo $img;?>.png" width="48" height="48" /></td><?php endfor;?>
- </tr>
- <tr class="day-param">
- <?php for($i = 0;$i < 4;$i++): // т.к. нам не нужны данные day_short и night_short, мы останавливаем проход на 4?>
- <td>
- <p><strong><?php echo $day->day_part[$i]->weather_type;?></strong></p>
- <p>ветер: <?php echo getWindDirection($day->day_part[$i]->wind_direction).' '.$day->day_part[$i]->wind_speed;?> м/с</p>
- <p>влажность: <?php echo $day->day_part[$i]->humidity;?>%</p>
- <p>давление: <?php echo $day->day_part[$i]->pressure;?> мм рт. ст.</p>
- </td>
- <?php endfor;?>
- </tr>
- </table>
- </div><?php
- endforeach;?>
- </div><?php
- endif;
- // получаем локализованную дату
- function getDayDate($date)
- {
- $date = strtotime($date);
- $months = array('','января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря');
- $days = array('воскресенье','понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота');
- return $days[date('w', $date)].', '.(int)date('d',$date).' '.$months[date('n', $date)];
- }
- // получаем знак температуры
- function getTempSign($temp)
- {
- $temp = (int)$temp;
- return $temp > 0 ? '+'.$temp : $temp;
- }
- // получаем направления ветра
- function getWindDirection($wind)
- {
- $wind = (string)$wind;
- $wind_direction = array('s'=>'↑ ю','n'=>'↓ с','w'=>'→ з','e'=>'← в','sw'=>'↗ юз','se'=>'↖ юв','nw'=>'↘ сз','ne'=>'↙ св');
- return $wind_direction[$wind];
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement