Posted By

Piotrek290 on 11/13/10


Tagged

php google xml simple weather


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

AllKnightAccess
jacoborus
verostudios


Google Weather


 / Published in: JavaScript
 

  1. <?php
  2. // Author: Piotr Filipek
  3. // Last Update: 12.11.2010
  4.  
  5. class GoogleWeather {
  6. protected $xml;
  7. public $now;
  8. public $days;
  9.  
  10. public function __construct($state){
  11. $this->weather = simplexml_load_file('http://www.google.com/ig/api?hl=pl&weather='.$state);
  12.  
  13. $this->now = $this->now();
  14. $this->days = $this->days();
  15. }
  16.  
  17. public function now(){
  18. return array(
  19. 'condition' => $this->weather->weather->current_conditions[0]->condition['data'],
  20. 'temp_f' => $this->weather->weather->current_conditions[0]->temp_f['data'],
  21. 'temp_c' => $this->weather->weather->current_conditions[0]->temp_c['data'],
  22. 'humidity' => $this->weather->weather->current_conditions[0]->humidity['data'],
  23. 'icon' => $this->weather->weather->current_conditions[0]->icon['data'],
  24. 'wind_condition' => $this->weather->weather->current_conditions[0]->wind_condition['data']
  25. );
  26. }
  27.  
  28. public function days(){
  29. $days = array();
  30.  
  31. foreach($this->weather->weather[0]->forecast_conditions as $conditions){
  32. $days[] = array(
  33. 'name' => $conditions->day_of_week['data'][0],
  34. 'low' => $conditions->low['data'][0],
  35. 'high' => $conditions->high['data'][0],
  36. 'icon' => "http://google.com".$conditions->icon['data'][0],
  37. 'condition' => $conditions->condition['data'][0],
  38. );
  39. }
  40.  
  41. return $days;
  42. }
  43. }
  44. ?>

Report this snippet  

You need to login to post a comment.