Advertisement
Guest User

Untitled

a guest
Sep 18th, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1.  
  2.     <?php
  3. $default_city = "LONDON";
  4. $default_lang = "en-GB";
  5. $city = ($_GET['city'] AND strlen($_GET['city']) > 0) ? $_GET['city'] : $default_city;
  6. $lang = ($_GET['lang'] AND strlen($_GET['lang']) > 0) ? $_GET['lang'] : $default_lang;
  7. // also you can (must) check input data like a preg_match('/([a-z]{2})|([a-z]{2})-([a-z]{2})/i')
  8. $xml = simplexml_load_file('http://www.google.com/ig/api?weather='.$city.'&hl='.$lang);
  9.  
  10. $information = $xml->xpath("/xml_api_reply/weather/forecast_information");
  11. $current = $xml->xpath("/xml_api_reply/weather/current_conditions");
  12. $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
  13. ?>
  14.  
  15.             <li class="now-img">
  16.                 <img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
  17.             </li>
  18.             <li class="now">
  19.                 <div class="now-name">
  20.                 Now
  21.                 </div>
  22.                 <div class="now-forecast">
  23.                 <?= $current[0]->temp_c['data'] ?>&deg; C / <?= $current[0]->temp_f['data'] ?>&deg; F
  24.                 </div>
  25.                 <div class="now-condition">
  26.                 <?= $current[0]->condition['data'] ?>
  27.                 </div>
  28.                 <div class="now-bottom">
  29.                     <div class="humidity left">
  30.                     Humidity<br/>
  31.                     8%
  32.                     </div>
  33.                     <div class="wind left">
  34.                     Wind<br/>
  35.                     SW at 27km/h
  36.                     </div>
  37.                 </div>
  38.             </li>
  39.             <? foreach ($forecast_list as $forecast) : ?>
  40.             <li class="line-break">
  41.             <img src="http://placehold.it/1x1" alt="weather"?>
  42.             </li>
  43.             <li class="day">
  44.                 <div class="day-name">
  45.                 <?= $forecast->day_of_week['data']; ?>
  46.                 </div>
  47.                 <div class="day-img">
  48.                 <img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
  49.                 </div>
  50.                 <div class="day-condition">
  51.                 <?= $forecast->condition['data'] ?>
  52.                 </div>
  53.                 <div class="day-forecast">
  54.                 <?= $forecast->low['data'] ?>&deg; C / <?= $forecast->high['data'] ?>&deg; ,
  55.                 </div>
  56.             </li>
  57.             <? endforeach ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement