Advertisement
Guest User

Untitled

a guest
Jun 9th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2.  
  3. $place=$_GET['place'];
  4. $current_temperature = "nan";
  5.  
  6. $ch = curl_init();
  7. $timeout = 5;
  8.  
  9. //Set CURL options
  10. curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/ig/api?weather=".$place."&hl=en");
  11. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  12. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  13.  
  14. $xml_str=curl_exec($ch);
  15.  
  16. //close CURL cause we dont need it anymore
  17. curl_close($ch);
  18.  
  19. $xml = new SimpleXmlElement($xml_str);
  20. $current_temperature = $xml->weather->current_conditions->temp_c["data"];
  21.  
  22. //echo $current_temperature;
  23. echo $current_temperature;
  24.  
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement