Free PHP Yahoo Weather Class!


This class delivers you the weather data from! 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!!!


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


Download the file from one of the following locations:


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.


$weather_chile = new weather("CIXX0020", 3600, "C"); // LocationCode, seconds cachelifetime, TempUnit (F or C)




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
  • (Go to, 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)
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 This may be very slow (needs every hit a connection to the Yahoo server!).
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, writes the object with a specified lifetime down to your local server! Very enhanced! Very usefull and VERY FAST!!


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

Attribute Description
locationtext  (unused)
locationcode The location code from
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
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!)