Advertisement
Guest User

Untitled

a guest
Aug 13th, 2014
3,552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.55 KB | None | 0 0
  1. <?php
  2. $city_id = 27612; // id Москвы
  3. $xml = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'weather_'.$city_id.'.xml';
  4. if(file_exists($xml)):
  5.     $data = simplexml_load_file($xml); //грузим ?>
  6.     <style type="text/css">
  7.     .weather{position:relative;border-bottom:1px solid #d5d5d5;padding-bottom:35px;}
  8.     .weather .date{font-size:13px;font-weight:700;padding-bottom:5px;text-transform:uppercase;border-bottom:1px solid #d5d5d5;margin-top:10px;}
  9.     .weather .item{background-color:#f0eedc;padding:15px;font-family:Georgia;margin-bottom:20px;}
  10.     .weather .item table{border:0;width:100%;}
  11.     .weather .item table td{padding-bottom:15px;width:20%;vertical-align:baseline;padding-right:5px;}
  12.     .weather .item .day-part td{font-size:18px;}
  13.     .weather .item .day-temp td{font-size:30px;}
  14.     .weather .item .day-temp td img{margin-left:5px;}
  15.     .weather .item .day-param td{font-size:12px;}
  16.     .weather .item .day-param td p{padding-bottom:3px;}
  17.     .weather .days{margin-top:35px;border:0;width:100%;}
  18.     .weather .days td{width:50%;padding-bottom:35px;}
  19.     .weather .days a{font-family:Georgia;font-size:18px;text-decoration:underline;font-weight:700;}
  20.     </style>
  21.     <div class="weather"><?php
  22.     foreach($data->day as $day):?>
  23.         <div class="date"><?php echo getDayDate($day['date']);?></div>
  24.         <div class="item">
  25.             <table>
  26.                 <tr class="day-part">
  27.                     <td>Утром</td>
  28.                     <td>Днем</td>
  29.                     <td>Вечером</td>
  30.                     <td>Ночью</td>
  31.                 </tr>
  32.                 <tr class="day-temp">
  33.                     <?php for($i = 0;$i < 4;$i++): // т.к. нам не нужны данные day_short и night_short, мы останавливаем проход на 4
  34.                     $img = $day->day_part[$i]->{'image-v3'};?>
  35.                     <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;?>
  36.                 </tr>
  37.                 <tr class="day-param">
  38.                     <?php for($i = 0;$i < 4;$i++): // т.к. нам не нужны данные day_short и night_short, мы останавливаем проход на 4?>
  39.                     <td>
  40.                         <p><strong><?php echo $day->day_part[$i]->weather_type;?></strong></p>
  41.                         <p>ветер: <?php echo getWindDirection($day->day_part[$i]->wind_direction).' '.$day->day_part[$i]->wind_speed;?> м/с</p>
  42.                         <p>влажность: <?php echo $day->day_part[$i]->humidity;?>%</p>
  43.                         <p>давление: <?php echo $day->day_part[$i]->pressure;?> мм рт. ст.</p>
  44.                     </td>
  45.                     <?php endfor;?>
  46.                 </tr>
  47.             </table>
  48.         </div><?php
  49.     endforeach;?>
  50.     </div><?php
  51. endif;
  52. // получаем локализованную дату
  53. function getDayDate($date)
  54. {
  55.     $date = strtotime($date);
  56.     $months = array('','января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря');
  57.     $days = array('воскресенье','понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота');
  58.     return $days[date('w', $date)].', '.(int)date('d',$date).' '.$months[date('n', $date)];
  59. }
  60. // получаем знак температуры
  61. function getTempSign($temp)
  62. {
  63.     $temp = (int)$temp;
  64.     return $temp > 0 ? '+'.$temp : $temp;
  65. }
  66. // получаем направления ветра
  67. function getWindDirection($wind)
  68. {
  69.     $wind = (string)$wind;
  70.     $wind_direction = array('s'=>'&#8593; ю','n'=>'&#8595; с','w'=>'&#8594; з','e'=>'&#8592; в','sw'=>'&#8599; юз','se'=>'&#8598; юв','nw'=>'&#8600; сз','ne'=>'&#8601; св');
  71.     return $wind_direction[$wind];
  72. }
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement