Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $default_city = "LONDON";
- $default_lang = "en-GB";
- $city = ($_GET['city'] AND strlen($_GET['city']) > 0) ? $_GET['city'] : $default_city;
- $lang = ($_GET['lang'] AND strlen($_GET['lang']) > 0) ? $_GET['lang'] : $default_lang;
- // also you can (must) check input data like a preg_match('/([a-z]{2})|([a-z]{2})-([a-z]{2})/i')
- $xml = simplexml_load_file('http://www.google.com/ig/api?weather='.$city.'&hl='.$lang);
- $information = $xml->xpath("/xml_api_reply/weather/forecast_information");
- $current = $xml->xpath("/xml_api_reply/weather/current_conditions");
- $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
- ?>
- <li class="now-img">
- <img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
- </li>
- <li class="now">
- <div class="now-name">
- Now
- </div>
- <div class="now-forecast">
- <?= $current[0]->temp_c['data'] ?>° C / <?= $current[0]->temp_f['data'] ?>° F
- </div>
- <div class="now-condition">
- <?= $current[0]->condition['data'] ?>
- </div>
- <div class="now-bottom">
- <div class="humidity left">
- Humidity<br/>
- 8%
- </div>
- <div class="wind left">
- Wind<br/>
- SW at 27km/h
- </div>
- </div>
- </li>
- <? foreach ($forecast_list as $forecast) : ?>
- <li class="line-break">
- <img src="http://placehold.it/1x1" alt="weather"?>
- </li>
- <li class="day">
- <div class="day-name">
- <?= $forecast->day_of_week['data']; ?>
- </div>
- <div class="day-img">
- <img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
- </div>
- <div class="day-condition">
- <?= $forecast->condition['data'] ?>
- </div>
- <div class="day-forecast">
- <?= $forecast->low['data'] ?>° C / <?= $forecast->high['data'] ?>° ,
- </div>
- </li>
- <? endforeach ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement