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:
<?phprequire('php-weather.inc.php');$oPhpWeather = new PhpWeather();// request weather for londonif ($oPhpWeather->Request('UKXX0085')) {$aCurrent = $oPhpWeather->GetCurrent();print_r($aCurrent);}?>
its good but it should increase its scope i.e. it should include forcasting also.
John - thanks for the feedback. I'll have a look and see what extra features are feasible for me to add.
hello nice script
Nice.
Is there a list of the City Code?
@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.
Sorry to clutter your post. I'm trying to see an example of your audio CAPTCHA.
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!!
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
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 ;)
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;
"//i"
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.