Free PHP Yahoo Weather Class!

V2.0
 

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!!! Thanks to Matt Brown for this new version.

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.weather2/weather.test.php (new window)
 

3) DOWNLOAD

Download the file from one of the following locations:

(use www.phpclasses.org or www.voegeli.li)
 

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", $cachedir);

// LocationCode, seconds cachelifetime, TempUnit (F or C), Directory for cache

$weather_chile->parsecached();

 

5) METHODS

The following methods are provided by the class.

 Method Description
Constructor Method:

object = new weather("CIXX0020", 3600, "C", $directory);

 


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)
  • $directory = temp cache dir
 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:

The classes attributes are all shown in the test-script attached! Please use this.