0

problem with the yahoo api weather

hello,
i was trying to embed the weather data into my site , i got
the code but it works for the title and the descriptions only and it
didnt work for the other data like the
city,region,timezone,sunrise,sunset,...... the all of the other things
didnt work . so here is my code and please tell me why it didnt work

CODE
<?

$feed_url = "http://weather.yahooapis.com/forecastrss?p=94089&u=c";

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

$xmlTwitter = curl_exec($curl);

curl_close($curl);

$xml = simplexml_load_string($xmlTwitter);


foreach ($xml->channel as $channel ){
$title = $channel->item->title;
$description = $channel->item->description;
$city = $channel->item->city;
$acttemp = $channel->item->acttemp;
$sunrise = $channel->item->sunrise;

}


echo "1-- ".$title;
echo "<br>";
echo "2-- ".$city;
echo "<br>";
echo "3-- ".$acttemp;
echo "<br>";
echo "4-- ".$sunrise;
echo "<br>";

?>


please guys i wanna display the all data like High temp, low temp, Sunset, Sunrise, Wind, Visibilit, Humidity, Feels Like.....and the same for the next days too. with no loaders or scripts , just simple code like the one i got .

please guys any help sad.gif

by
1 Reply
  • This is a great case for using yql public weather api, see example:

    CODE
    <?php

    $yql_public_api = 'http://query.yahooapis.com/v1/public/yql?format=json&q=';

    $yql = "SELECT * FROM weather.forecast WHERE location = 94089";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $yql_public_api.urlencode($yql));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

    $data = json_decode(curl_exec($curl));
    $weather = $data->query->results->channel;

    curl_close($curl);

    echo $weather->title;

    echo $weather->location->city;

    echo $weather->item->condition->temp;

    echo $weather->astronomy->sunrise;



    QUOTE (freesoul.info @ Feb 19 2009, 07:28 AM) <{POST_SNAPBACK}>
    hello,
    i was trying to embed the weather data into my site , i got
    the code but it works for the title and the descriptions only and it
    didnt work for the other data like the
    city,region,timezone,sunrise,sunset,...... the all of the other things
    didnt work . so here is my code and please tell me why it didnt work

    CODE
    <?

    $feed_url = "http://weather.yahooapis.com/forecastrss?p=94089&u=c";

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL,"$feed_url");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

    $xmlTwitter = curl_exec($curl);

    curl_close($curl);

    $xml = simplexml_load_string($xmlTwitter);


    foreach ($xml->channel as $channel ){
    $title = $channel->item->title;
    $description = $channel->item->description;
    $city = $channel->item->city;
    $acttemp = $channel->item->acttemp;
    $sunrise = $channel->item->sunrise;

    }


    echo "1-- ".$title;
    echo "<br>";
    echo "2-- ".$city;
    echo "<br>";
    echo "3-- ".$acttemp;
    echo "<br>";
    echo "4-- ".$sunrise;
    echo "<br>";

    ?>


    please guys i wanna display the all data like High temp, low temp, Sunset, Sunrise, Wind, Visibilit, Humidity, Feels Like.....and the same for the next days too. with no loaders or scripts , just simple code like the one i got .

    please guys any help :(
    0
This forum is locked.

Recent Posts

in Y!OS Policy Questions