Weather station scripts

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

This page was updated Wednesday, 13-Jun-2018 8:56 PM

WeatherUnderground International forecast formatting script - multilingual

Note: on 29-Oct-2014, WeatherUnderground changed their page layout for forecasts and necessitated a fairly complete rewrite of the WU-forecast.php script to Version 3.x. Since WeatherUnderground no longer includes forecast JSON data in the page, the V3.x script uses the WU API to get the forecast data for the script. To use it, you must acquire an API Key at
Register for the Developer class key -- it is free/no-cost. The script will cache the JSON returns from the API so only one API access per forecast, per language is done per hour and that is well under the allowed accesses per day for the Developer class key.

I started this script based on a Perl script I had used to extract the Weather Underground forecast for my area to post on my original 1-page website. Thanks to interest from others to use a modified version of that script for international forecasts, I thought it was a good idea to make WU forecast output available in multiple languages (since the WU site supports translations). I wrote the WU-forecast.php to create a carterlake-style forecast output that would use the saratoga (NOAA) icon set (or the WU Icon set), would be easy to include in a weather website, and have built-in support for translations to other languages based on those languages provided by WeatherUnderground.

Legal Stuff -- please read and heed...

Unlike the carterlake/NOAA forecast script which reads the public domain NWS websites, this script reads and processes the WU API JSON feed from, which contains copyrighted material. WU has a very stringent (and somewhat strident) Terms of Use that on first reading seems to prohibit any usage of their site, even by personal, non-commercial websites who's owners are contributing their weather data to Weather Underground. The ToS seems to prohibit even the common usage by VWS templates (and my AJAXed versions) which make extensive use of WU forecast, graphics and data in their design.

In a series of mail messages and forum postings, the intent of WU is to allow fair usage of their graphics and data for personal, non-commercial stations that contribute data to WeatherUnderground was stated. Here's the message with that information:


My name is John Celenza and I am the Director of Weather Technology at Wunderground.

Please let me explain.

It is not Weather Underground's intention to disallow folks to use our graphics and data on their personal/non-commercial web sites.

Please feel free to use Wunderground images and data on personal sites, as long as you link those images to Wunderground or give direct credit. Something like "This image courtesy of Weather Underground" is appropriate.

We sincerely appreciate the contributions folks have made to our community. And, we are in no way an organization trying to take...take...take and not give. Our philosophy couldn't be farther from that.

Hopefully we can make the Terms of Service more clear soon.

Thank you!


So, in order to use this script you need to:

  1. Have your weather station submit data to WeatherUnderground as a WU member.
  2. Register for and acquire a free WU API key.
  3. Use this script ONLY on your personal, non-commercial weather station website.
  4. Leave attribution (and hotlink) to WeatherUnderground as the source of the data.

Adhere to these four requirements, and you should have fair use of this data from Weather Underground.

Settings in the WU-forecast.php script

// Settings ---------------------------------------------------------------
//REQUIRED: a WU API KEY.. sign up at
$WUAPIkey = 'specify-for-standalone-use-here'; // use this only for standalone / non-template use
// NOTE: if using the Saratoga template, add to Settings.php a line with:
//    $SITE['WUAPIkey'] = 'your-api-key-here';
// and that will enable the script to operate correctly in your template
$iconDir ='./forecast/images/';	// directory for carterlake icons './forecast/images/'
$iconType = '.jpg';				// default type='.jpg' 
//                            		use '.gif' for animated icons from
//$iconDir ='';					// set to '' to use the Wunderground icons instead
$WU_URL = '';
// The optional multi-city forecast .. make sure the first entry is for the $WU_URL location
// The contents will be replaced by $SITE['WUforecasts'] if specified in your Settings.php

$WUforecasts = array(
 // Location|forecast-URL  (separated by | characters)
'Auckland|', // Awhitu, Waiuku New Zealand
'Tel Aviv|',
'Canvey Island, Essex|',
'Saratoga PWS|',
$maxWidth = '640px';                      // max width of tables (could be '100%')
$maxIcons = 10;                           // max number of icons to display
$maxForecasts = 14;                       // max number of Text forecast periods to display
$maxForecastLegendWords = 4;              // more words in forecast legend than this number will use our forecast words 
$numIconsInFoldedRow = 5;                 // if words cause overflow of $maxWidth pixels, then put this num of icons in rows
$autoSetTemplate = true;                  // =true set icons based on wide/narrow template design
$cacheFileDir = './';                     // default cache file directory
$cacheName = "WU-forecast-json.txt";      // locally cached page from WU
$refetchSeconds = 3600;                   // cache lifetime (3600sec = 60 minutes)
$xlateCOP = 'Chance of precipitation';    // change to local language if needed like
//$xlateCOP = 'Kans op neerslag';   //  Dutch example
$showTempsAs  = 'C';                  // under icons/forecast, 'C'=Centigrade, 'F'=Fahrenheit
$charsetOutput = 'ISO-8859-1';        // default character encoding of output
$lang = 'en';	// default language
$foldIconRow = true;  // display icons in rows of 5 if long texts are found
$RTLlang = ',he,jp,cn,';  // languages that use right-to-left order
// ---- end of settings ---------------------------------------------------

For Saratoga template users, you normally do not have to customize the script itself as the most common configurable settings are maintained in your Settings.php file. This allows you to just replace the WU-forecast.php on your site when new versions are released. With V3.00, you DO have to add a $SITE['WUAPIkey'] = 'your-key-here'; entry to your Settings.php file to support this and future releases of the script.

$WUAPIkey = 'specify-for-standalone-use-here';
This setting is for standalone use (do not change this for Saratoga templates).
Register for a WU API Key at and replace specify-for-standalone-use-herei> with the registered API key. The script will nag you if this has not been done.

For Saratoga template users, do the registration at the WU API site above, then put your API key in your Settings.php as:

$SITE['WUAPIkey'] = 'your-key-here';

to allow easy future updates of the WU-forecast.php script by simple replacement.
This setting controls whether to display the NOAA-styled icons or the WeatherUnderground icons on the forecast display.
Set $iconDir = ''; to use the WeatherUnderground icons.
Set $iconDir to the relative file path to the Saratoga Icon set (same set as used with the WXSIM plaintext-parser.php script).
Be sure to include the trailing slash in the directory specification as shown in the example above.
Saratoga template users: Use the Settings.php entry for $SITE['fcsticonsdir'] to specify this value.
This setting controls the extension (type) for the icon to be displayed.
='.jpg'; for the default Saratoga JPG icon set.
='.gif'; for the Meteotriviglio animated GIF icon set.
Saratoga template users: Use the Settings.php entry for $SITE['fcsticonstype'] to specify this value.
This is the full URL for the WeatherUnderground page containing the forecast. Find it by searching on WU for a nearby city to your weather station location. Copy the full URL from your browser address bar to the area between the single quotes. Please note that some WU translations may be incomplete as not all words/phrases may be translated from English. Also note that changing from English may involve using different character sets than the ISO-8859-1 Latin set. The script will produce HTML with a <meta> tag specifying the character set -- if you include the script in a page, make sure the including page uses the character set of the WU page otherwise your output page may be garbled and unreadable.
Saratoga template users: Use the Settings.php entry for $SITE['fcsturlWU'] to specify this value.
$WUforecasts = array(
// Location|forecast-URL (separated by | characters)
This setting is an alternative method of specifying the locations for forecasts. If used, it will override the main location specified in the $WU_URL above and allow the viewer to choose between forecasts for different areas based on a drop-down list box selection.
Saratoga template users: Use the Settings.php entry for $SITE['WUforecasts'] = array(...); to specify the list of sites and URLs.
This variable controls the maximum width of the tables for the icons and text display. It may be in pixels (as shown), or '100%'. The Saratoga/NOAA icons are 55px wide and there are up to 14 icons, so beware setting this width too small as the display may be quite strange.
This variable specifies the maximum number of icons to display in the graphical part of the forecast. Some forecast locations may have up to 7 days of forecast (14 icons) so be careful how wide the forecast may become on the page.
This setting specifies the directory to store the cache files. The default is the same directory in which the script is located.
Include the trailing slash in the directory specification.
Saratoga template users: Use the Settings.php entry for $SITE['cacheFileDir'] to specify this value.
This variable specifies the name of the cache file for the WU forecast page.
This variable specifies the cache lifetime, or how long to use the cache before reloading a copy from Weather Underground. The default is 3600 seconds (60 minutes). Forecasts don't change very often, so please don't reduce it below 60 minutes to minimize your API access count and keep it to the free Developer API range.
This setting is used to replace the phrase 'Chance of precipitation' with the same phrase in your language. Currently, Wunderground doesn't have this phrase translated in the non-English websites
Saratoga template users: Use the Settings.php entry for $SITE['xlateCOP'] to specify this value.
This setting controls how the temperatures are displayed below the condition icons.
='C' will display temperatures in Centigrade below the icons and metric units (C,km/s,hPa,mm) in the text forecast. (Default)
='F' will display temperatures in Fahrenheit below the icons and imperial units (F,mph,inHg,in) in the text forecast.
Saratoga template users: This setting will be overridden by the default temperature units specified in your Settings.php.
This setting controls 'folding' of the icons into two rows if the aggregate width of characters exceeds the $maxSize dimension in pixels.
= true; is the default (fold the row)
= false; to select not to fold the row.
Saratoga template users: Use the Settings.php entry for $SITE['foldIconRow'] to specify this value.

More documentation is contained in the script itself about variable names/arrays made available, and the contents. The samples below serve to illustrate some of the possible usages on your weather website.

Usage samples

$doIncludeWU = true;
include("WU-forecast.php"); ?>


WeatherUnderground 7-day Forecast: Aaby
Friday Friday Night Saturday Saturday Night Sunday
Partly cloudy Some clouds Partly cloudy Partly cloudy Partly cloudy
Partly cloudy Some clouds Partly cloudy Partly cloudy Partly cloudy
40°F 33°F 46°F 35°F 52°F
Sunday Night Monday Monday Night Tuesday Tuesday Night
Partly cloudy skies Mostly cloudy Considerable cloudiness Partly cloudy Generally fair
Partly cloudy skies Mostly cloudy Considerable cloudiness Partly cloudy Generally fair
37°F 51°F 41°F 54°F 40°F


Partly cloudy. Lows overnight in the low 30s.
Friday Night
Some clouds. Low 33F. Winds S at 5 to 10 mph.
Some sun in the morning with increasing clouds during the afternoon. High 46F. Winds SSW at 5 to 10 mph.
Saturday Night
Some clouds early will give way to generally clear conditions overnight. Low near 35F. Winds SW at 5 to 10 mph.
Partly cloudy skies in the morning will give way to cloudy skies during the afternoon. High 52F. Winds W at 5 to 10 mph.
Sunday Night
Partly cloudy skies. Low 37F. Winds W at 5 to 10 mph.
Mostly cloudy. High 51F. Winds W at 10 to 15 mph.
Monday Night
Considerable cloudiness. Low 41F. Winds WNW at 10 to 15 mph.
Cloudy early with partial sunshine expected late. High 54F. Winds W at 5 to 10 mph.
Tuesday Night
Generally fair. Low around 40F. Winds W at 5 to 10 mph.
Partly cloudy skies. High 53F. Winds W at 10 to 15 mph.
Wednesday Night
Considerable clouds early. Some decrease in clouds late. Low 39F. Winds WNW at 10 to 15 mph.
Intervals of clouds and sunshine. High 49F. Winds WNW at 10 to 20 mph.
Thursday Night
Partly cloudy. Low 38F. Winds W at 5 to 10 mph.


Forecast from WeatherUnderground for Aaby.

You can also include it 'silently' and print just a few (or all) the contents where you'd like it on the page

$doPrintWU = false;
require("WU-forecast.php"); ?>

then on your page, the following code would display just the current and next time period forecast:

<tr align="center" valign="top">
<?php print "<td>$WUforecasticons[0]</td><td>$WUforecasticons[1]</td>\n"; ?>
<tr align="center" valign="top">
<?php print "<td>$WUforecasttemp[0]</td><td>$WUforecasttemp[1]</td>\n"; ?>
Partly cloudy
Partly cloudy
Friday Night
Some clouds
Some clouds

Or if you'd like to include the immediate forecast with text for the next two cycles:

<tr valign="top">
<?php print "<td align=\"center\">$WUforecasticons[0]<br />$WUforecasttemp[0]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$WUforecasttext[0]</td>\n"; ?>
<tr valign="top">
<?php print "<td align=\"center\">$WUforecasticons[1]<br />$WUforecasttemp[1]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$WUforecasttext[1]</td>\n"; ?>

Partly cloudy
Partly cloudy
Partly cloudy. Lows overnight in the low 30s.
Friday Night
Some clouds
Some clouds
Some clouds. Low 33F. Winds S at 5 to 10 mph.

If you'd like to style the output, you can easily do so by setting a CSS for class WUforecast either in your CSS file or on the page including the WU-forecast.php (in include mode):

<style type="text/css">  
.WUforecast {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9pt;

Installation of WU-forecast.php

Download WU-forecast.php from the link below.

Optionally, download the Icon set (or just the Add-on Icons if you already have the Carterlake NOAA Icon set), and upload to /forecast/images directory. If you already have the plaintext-parser.php WXSIM script installed, you can use the existing icon set (no need to download again).

Change settings in WU-forecast.php for the $WU_URL address and the address of the icons if necessary and upload the modified WU-forecast.php to your website.

Ensure the permission on "WU-forecast.txt" cache file are at least 666 or 766 so the file is writable by the WU-forecst.php script

Download: WU-forecast.php (ML Version 3.05 - 13-Jun-2018 for old WD/PHP/World-ML or Base-World template set)
Note: as of ML Version 1.26, the script should be usable for Standalone or old WD/PHP/World V2 template use also.
Note: as of V2.00, the script requires PHP 5.3+ to operate correctly.

Download: Icon Set (upload to your website in the /forecast/images directory)