Pressure is nothing more than the shadow of great opportunity. - Michael Johnson

Library for accessing Yahoo! Weather RSS feeds

4 years, 5 months ago

I've added a new PHP library to the site which gives easy access to the Weather RSS feeds provided by the Yahoo! Developer Network. Simply pass a valid weather code (or US ZIP code for US locations). The Weather RSS feeds page has details of how to obtain valid codes to use. Weather data is available for all countries. The library provides methods to retrieve current conditions, forecast data for today & tomorrow, wind chill/direction/speed, geo-location as well as a number of other details.

It also includes integrated caching of retrieved data which it parses using regular expressions. The use of regular expressions rather than a real parser might not be to everybody's liking, but it does make the library very simple and means there are no dependancies on external libraries.

A simple example of usage is shown below:

  1. <?php
  2. require('php-weather.inc.php');
  3. $oPhpWeather = new PhpWeather();
  4. // request weather for london
  5. if ($oPhpWeather->Request('UKXX0085')) {
  6. $aCurrent = $oPhpWeather->GetCurrent();
  7. print_r($aCurrent);
  8. }
  9. ?>

Click here to download the library.

Comments

  • its good but it should increase its scope i.e. it should include forcasting also.

    John - 6th June 2006 #

  • John - thanks for the feedback. I'll have a look and see what extra features are feasible for me to add.

    Ed Eliot - 7th June 2006 #

  • hello nice script

    fernan - 18th June 2006 #

  • Nice.

    Is there a list of the City Code?

    Dinoboff - 11th August 2006 #

  • @Dinoboff - There isn't a list at the moment but try searching for a city on weather.yahoo.com. The URL for the resulting weather page should give you the code you're after.

    Ed Eliot - 13th August 2006 #

  • Sorry to clutter your post. I'm trying to see an example of your audio CAPTCHA.

    Fred - 7th March 2007 #

  • Thanks for this library dude!, it took me 1 day developing to get pissed off and then I went to google and found this library i felt dumb. Anyways thanks for writing this library.

    Another thing... found a bug in the library and wanted to report it for others who download the library:

    In the forecast function to get both day you have to send the day in the function, but the if condition is wrong only have 1 equal sign "=" should be 2 equals signs "==".

    in line 100 (weather.inc.php): if ($sDay = 'today') {

    Thanks for writing this again!!

    Giancarlo Alfau - 4th April 2007 #

  • Ed,

    He intentado usar tu código que mencionas arriba, subí los archivos weather.inc.php y cache.inc.php al servidor pero el resultado que conseguí es este: Array ( [text] => Mostly Cloudy [code] => 28 [temp] => 27 [date] => Thu, 12 Apr 2007 8:47 am CDT )

    me parece que esta bien la información pero me gustaría sleccionarla, utilizando solo la temperatura.

    No entiendo porque, si puedes ayudarme te lo agradecería casi no se mucho de php

    Atentamente Jorge

    JOrge - 12th April 2007 #

  • Hi... I used for 3 weeks and it work perfect but suddenly stoped and there was no data, nothing the code I used was une of Usuahia in Argentina "ARTF0105" I don't understand why it happend!! if I use "ARBA0009" the code from buenos aires and it work, but the funny thing is when I use the path http://xml.weather.yahoo.com/forecastrss?p=ARTF0105&u=c I see all the information... so I though that the problem is on the code... the way it read the file... but I don't know. There is a posibility that you may help me. Thanks anyway for the script it was very usefull ;)

    Lara - 27th November 2007 #

  • Hi, The first regex for the GetTagAttributes function has a slight issue ...

    This will ignore any yweather:forecast with a '/' in the them such as text="Rain/Snow".

    Looking at the XML that the Yahoo RSS feed dishes out, there doesn't seem to be any need to strip '/' from the code for the GetTagAttributes function so I have this working ok using a simpler regex as follows;

    Arash - 13th January 2008 #

  • "//i"

    Arash - 13th January 2008 #

  • Hi, I have noticed that starting from today the getForecast function doesnt work anymore :( can you replicate please the issue and advice us if there is anything that could be done? thanks in advance.

    vasile - 8th April 2008 #

  • chat | Porno izle | sex izle | sicak sohbet Dear Admin, I thank you for this informative article. And I thank you for this I follow your vendors. It’s verry good. I wish you continued success whould you like. sicak chat | sohbet | chat | sohbet siteleri | chat siteleri | sohbetim | sohbet siteleri | This is a great resource for growing your buisness.There are various aspects in buiness management and to grow the business.This is a very useful for tool for young entepreneurs. Thanks You Admin chat siteleri | sohbet odalari | chat odalari - sohbet - sohbet kanalları - chat kanalları - mynet sohbet | Chat Sitesi

    kimene - 4th August 2010 #

Help make this post better

Notes: Standard BBCode for links, bold, italic and code are supported. rel="nofollow" is added to all links. Your email address will never be displayed on the site.

Back to index