Free PHP Yahoo Weather Class!

1) WHAT IT IS?!

This class delivers you the weather data from http://weather.yahoo.com! It uses the free RSS stream from yahoo. The class is very easy to use. Also an automatically caching is integrated. So the rss has not to be loaded every hit to the page! You can define the cache lifetime by your self. Enjoy it!!!

2) DEMO

The demo is available by clicking on the following link! This test script shows you all attributes, that the class delivers!

http://www.voegeli.li/development/class.yahoo.weather/weather.test.php (new window)

3) DOWNLOAD

Download the file from one of the following locations:

http://www.voegeli.li/development/class.yahoo.weather/class.yahoo.weather.rar

4) USAGE EXAMPLE (VERY EASY)

Take a look at the following using example! This is taken from the test script, which is included in the download archive. If you want t know more about attributes and methods, read the following points.
include("class.xml.parser.php");
include("class.weather.php");
$weather_chile = new weather("CIXX0020", 3600, "C"); // LocationCode, seconds cachelifetime, TempUnit (F or C)
$weather_chile->parsecached();

5) METHODS

The following methods are provided by the class.

Method | Description
Constructor Method: object = new weather("CIXX0020", 3600, "C"); | This is the constructor method, automatically called, when you make the instance. There are 3 Parameters you have to pass: "CIXX0020" = Location Code from weather.Yahoo.com (Go to weather.yahoo.com, search in the browser for location, click on location link and look in the browsers URL field for the Code Param (at the end!) 3600 = 3600 seconds (1 hour) lifetime of the cache object. By using method parsecached() this defines, when the RSS has to be automatically reparsed from RSS (If not needed pass "0") "C" = Celsius. This is the unir, in which the temperature should be taken ("F" = Fahrenheit / "C" = Celsius)
parse() | This method parses the weather data from RSS every call!!! That means every time, when you call this method, the weather data are refreshed from the RSS from weather.yahoo.com. This may be very slow (needs every hit a connection to the Yahoo server!). NOT RECOMMENDED
parsecached() | This method parses the RSS only if needed! That means it looks on your local server, if there's a valid object cache file (named like the location code). If there is no cached version, it automatically parses the object from RSS weather.yahoo.com, writes the object with a specified lifetime down to your local server! Very enhanced! Very usefull and VERY FAST!! RECOMMENDED!!!

6) ATTRIBUTES

Here is the complete list of the class attributes with a description:

Attribute | Description
locationtext | (unused)
locationcode | The location code from weather.yahoo.com
allurl | RSS URL (full)
title | Text from Yahoo (Yahoo! Weather - Santiago, CI)
city | City (Santiago)
sunrise | Time of sunrise
sunset | Time of sunset
yahoolink | Link to the actual forecast details on weather.yahoo.com
acttext | Actual Situation: Text
acttemp | Actual Situation: Temperature
acttime | Actual Situation: Time of measure
imageurl | Actual Situation: Logo from yahoo
actcode | Actual Situation: Weather code (see testscript images!)
fore_day1_day (DAY1) | Forecast: Day ("Wed", "Thu"...)
fore_day1_date | Forecast: Date
fore_day1_tlow | Forecast: Temp low (night)
fore_day1_thigh | Forecast: Temp high (day)
fore_day1_text | Forecast: Text
fore_day1_imgcode | Forecast: Weather code (see testscript images!)
fore_day2_day (DAY2) | Forecast: Day ("Wed", "Thu"...)
fore_day2_date | Forecast: Date
fore_day2_tlow | Forecast: Temp low (night)
fore_day2_thigh | Forecast: Temp high (day)
fore_day2_text | Forecast: Text
fore_day2_imgcode | Forecast: Weather code (see testscript images!)
fore_day3_day (DAY3) | Forecast: Day ("Wed", "Thu"...)
fore_day3_date | Forecast: Date
fore_day3_tlow | Forecast: Temp low (night)
fore_day3_thigh | Forecast: Temp high (day)
fore_day3_text | Forecast: Text
fore_day3_imgcode | Forecast: Weather code (see testscript images!)
fore_day4_day (DAY4) | Forecast: Day ("Wed", "Thu"...)
fore_day4_date | Forecast: Date
fore_day4_tlow | Forecast: Temp low (night)
fore_day4_thigh | Forecast: Temp high (day)
fore_day4_text | Forecast: Text
fore_day4_imgcode | Forecast: Weather code (see testscript images!)
fore_day5_day (DAY5) | Forecast: Day ("Wed", "Thu"...)
fore_day5_date | Forecast: Date
fore_day5_tlow | Forecast: Temp low (night)
fore_day5_thigh | Forecast: Temp high (day)
fore_day5_text | Forecast: Text
fore_day5_imgcode | Forecast: Weather code (see testscript images!)