0

How to Display the Temperature (weather api ) in the blog using php

Dear All,

I want to display the temperature of my country on my personal blog. And I found some tutorial about display the (weather condition=text) and the lengthy (weather description). However, I just want to display the Temperature ONLY. How can I do this?

here is the tutorial: http://css-tricks.com/using-weather-data-t...gh-php-and-css/


thanks

rudy

by
1 Reply
  • Rudy,

    You can use any xml parser like DOM,SimpleXML to extract the temperature.
    http://php.net/manual/en/book.simplexml.php
    http://php.net/manual/en/book.dom.php

    Sample code using SimpleXML:
    <?php
    $cl = curl_init("http://weather.yahooapis.com/forecastrss?w=123456&u=f");
    curl_setopt($cl,CURLOPT_RETURNTRANSFER,true);
    $sxe = simplexml_load_string(curl_exec($cl));
    $ns = $sxe->getDocNamespaces();
    $sxe->registerXPathNamespace('yweather',$ns['yweather']);
    $temp = $sxe->xpath("/rss/channel/item/yweather:condition/@temp");
    print $temp[0]."\n"; //Prints the temperature in F
    ?>

    Robyn Tippins
    community manager, YDN
    0
This forum is locked.

Recent Posts

in Local API - General Questions