Return to Snippet

Revision: 27575
at June 17, 2010 01:30 by silverskymedia


Initial Code
<?php
function retrieveYahooWeather($zipCode="84015") {
    $yahooUrl = "http://weather.yahooapis.com/forecastrss";
    $yahooZip = "?p=$zipCode";
    $yahooFullUrl = $yahooUrl . $yahooZip; 
    $curlObject = curl_init();
    curl_setopt($curlObject,CURLOPT_URL,$yahooFullUrl);
    curl_setopt($curlObject,CURLOPT_HEADER,false);
    curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);
    $returnYahooWeather = curl_exec($curlObject);
    curl_close($curlObject);
    return $returnYahooWeather;
}
$localZipCode = "84015"; // Clearfield, UT
$weatherXmlString = retrieveYahooWeather($localZipCode);
$weatherXmlObject = new SimpleXMLElement($weatherXmlString);
$currentCondition = $weatherXmlObject->xpath("//yweather:condition");
$currentTemperature = $currentCondition[0]["temp"];
$currentDescription = $currentCondition[0]["text"];
?>

Initial URL
weather, yahoo, rss, php

Initial Description

                                

Initial Title
Yahoo! Weather RSS Parsing

Initial Tags

                                

Initial Language
PHP