Pythorian

[PHP] Get Weather Forecast

Sep 10th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. <?php
  2. //source from http://stackoverflow.com/questions/4035742/parse-json-in-php
  3. //updated api url and minor code tweaks
  4.  
  5. $json = json_decode(file_get_contents("http://free.worldweatheronline.com/feed/weather.ashx?q=98105&format=json&num_of_days=5&key=8f2d1ea151085304102710"), true);
  6.  
  7. foreach($json['data']['weather'] as $item) {
  8.     print $item['date'];
  9.     print ' - ';
  10.     print $item['weatherDesc'][0]['value'];
  11.     print ' - ';
  12.     print '<img src="' . $item['weatherIconUrl'][0]['value'] . '" border="0" alt="" />';
  13.     print '<br>';
  14. }
  15. ?>
Advertisement
Add Comment
Please, Sign In to add comment