Posted By

silverskymedia on 06/17/10


Tagged


Versions (?)

Yahoo! Weather RSS Parsing


 / Published in: PHP
 

URL: weather, yahoo, rss, php

  1. <?php
  2. function retrieveYahooWeather($zipCode="84015") {
  3. $yahooUrl = "http://weather.yahooapis.com/forecastrss";
  4. $yahooZip = "?p=$zipCode";
  5. $yahooFullUrl = $yahooUrl . $yahooZip;
  6. $curlObject = curl_init();
  7. curl_setopt($curlObject,CURLOPT_URL,$yahooFullUrl);
  8. curl_setopt($curlObject,CURLOPT_HEADER,false);
  9. curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);
  10. $returnYahooWeather = curl_exec($curlObject);
  11. curl_close($curlObject);
  12. return $returnYahooWeather;
  13. }
  14. $localZipCode = "84015"; // Clearfield, UT
  15. $weatherXmlString = retrieveYahooWeather($localZipCode);
  16. $weatherXmlObject = new SimpleXMLElement($weatherXmlString);
  17. $currentCondition = $weatherXmlObject->xpath("//yweather:condition");
  18. $currentTemperature = $currentCondition[0]["temp"];
  19. $currentDescription = $currentCondition[0]["text"];
  20. ?>

Report this snippet  

You need to login to post a comment.