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

Report this snippet  

You need to login to post a comment.