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.

Many of these scripts are now available on GitHub at

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 Friday, 22-Mar-2019 9:00 AM

WU/TWC International forecast formatting script - multilingual

Note: on 27-Feb-2019, WU announced the method to acquire WU/TWC API keys which are available ONLY for stations submitting PWS data to As such, you MUST be a member of WeatherUnderground and have a PWS submitting data in order to acquire an API key to use this script.

This script is based on the WU-forecast.php script which is now deprecated as WeatherUnderground has turned off the WU API keys as of 21-Mar-2019.
The script REQUIRES an API KEY for (which is NOT the same as the old WU API key). The key is available ONLY to PWS data submitters to
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 API key by the procedure below.
  3. Use this script ONLY on your personal, non-commercial weather station website.
  4. Leave attribution (and hotlink) to as the source of the data.

Adhere to these four requirements, and you should have fair use of this data from WeatherUnderground/

How to get a WU/TWC API Key

  • Use your browser to open
  • If you are not logged in, you will be asked to. The system will also verify that you have a PWS uploading to the system.
  • You will then see a blank box below “Your API keys”.
    Agree to the new Terms and Conditions by clicking in the small box next to “I agree”, click on the blue “GENERATE” box, and your new key will be created.

    The key will be masked on the screen, but you can use the “Show” link below the box to see it.
    There is also another blue box, which, when clicked, copies the key to your clipboard.
  • Save that key in the $WCAPIkey in the script for standalone use, or if using a Saratoga template, save in Settings.php in a $SITE['WCAPIkey'] setting.

Settings in the WC-forecast.php script

// Settings ---------------------------------------------------------------
//REQUIRED: a WU API KEY.. sign up at
$WCAPIkey = '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['WCAPIkey'] = 'your-api-key-here';
// and that will enable the script to operate correctly in your template
// Select which units will be used for the displays:
//$WCunits  = 'e';  // 'e'= US units F,mph,inHg,in,in
$WCunits  = 'm';  // 'm'= metric   C,km/h,hPa,mm,cm
//$WCunits  = 'h';  // 'h'= UK units C,mph,mb,mm,cm
//$WCunits  = 's';  // 's'= SI units C,m/s,hPa,mm,cm
$iconDir ='./forecast/images/';	// directory for carterlake icons './forecast/images/'
$iconType = '.jpg'; // default type='.jpg' 
//                     use '.gif' for animated icons from
$WC_LOC = 'Saratoga, CA, USA|37.27465,-122.02295';
// The optional multi-city forecast .. make sure the first entry is for the $WC_LOC location
// The contents will be replaced by $SITE['WCforecasts'] if specified in your Settings.php

$WCforecasts = array(
 // Location name to display|lat,long  (separated by | character)
'Saratoga, CA, USA|37.27465,-122.02295',
'Auckland, NZ|-36.910,174.771', // Awhitu, Waiuku New Zealand
'Assen, NL|53.02277,6.59037',
'Blankenburg, DE|51.8089941,10.9080649',
'Cheyenne, WY, USA|41.144259,-104.83497',
'Carcassonne, FR|43.2077801,2.2790407',
'Braniewo, PL|54.3793635,19.7853585',
'Omaha, NE, USA|41.19043,-96.13114',
'Johanngeorgenstadt, DE|50.439339,12.706085',
'Athens, GR|37.97830,23.715363',
'Haifa, IL|32.7996029,34.9467358',
'Tahoe Vista, CA, USA|39.2403,-120.0528',
'Auburn, CA, USA|38.8962,-121.0789',
$commaDecimal = false;                 // set to true to process numbers with a comma for a decimal point
$maxWidth = '640px';                   // max width of tables (could be '100%')
$maxForecastLegendWords = 4;           // more words in forecast legend than this number will use our forecast words 
$autoSetTemplate = true;               // =true; set icons based on wide/narrow template design
//                                     // =false; don't autoset maxWidth based on Saratoga wide/narrow 
$foldIconRow = true;                   // =true; display icons in rows of 5 if long texts are found
$iconRowDayNight = true;               // =false; 9 icons in a row, folded over if long texts.
//                                     // =true;  icons always in two rows Day over Night
$cacheFileDir = './';                  // default cache file directory
$cacheName = "WC-forecast-json.txt";   // locally cached page from WC
$refetchSeconds = 3600;                // cache lifetime (3600sec = 60 minutes)
$charsetOutput = 'ISO-8859-1';         // default character encoding of output ='ISO-8859-1' for Saratoga templates
$lang = 'en';                          // default language ='en' for English
// ---- end of settings ---------------------------------------------------
$WCAPIkey = 'specify-for-standalone-use-here';
This setting is for standalone use (do not change this for Saratoga templates).
Register for a WU/TWC 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 WC-forecast.php script by simple replacement.
$WCunits = 'm';
Use this to set the units used in the forecasts:
= 'e'; // 'e'= US units F,mph,inHg,in,in
= 'm'; // 'm'= metric C,km/h,hPa,mm,cm (default)
= 'h'; // 'h'= UK units C,mph,mb,mm,cm
= 's'; // 's'= SI units C,m/s,hPa,mm,cm

For Saratoga template users, insert $SITE['WCunits'] = 'm';in your Settings.php.
This setting controls whether to display the NOAA-styled icons or the WeatherUnderground icons on the forecast display.
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.
$WC_LOC = 'Saratoga, CA, USA|37.27465,-122.02295';
This is the default location for the forecast.
Saratoga template users: Use the Settings.php entry for $SITE['fcsturlWC'] to specify this value.
$WCforecasts = array(
// Location name to display|lat,long (separated by | character)
'Saratoga, CA, USA|37.27465,-122.02295',
'Auckland, NZ|-36.910,174.771', // Awhitu, Waiuku New Zealand
This setting is an alternative method of specifying the locations for forecasts. If used, it will override the main location specified in the $WC_LOC 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['WCforecasts'] = array(...); to specify the list of sites and lat/long.
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 5 days of forecast (10 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. Note that unit and language values are appended to the file name so the change of units or language can be honored.
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 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.
This setting overrides $foldIconRow setting and always displays two rows of icons - Day over Night icon
=true; to always display Day over Night icons
=false; to follow the $foldIconRow setting (use two rows only if text conditions are two long to fit in one row)

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

$doIncludeWC = true;
include("WC-forecast.php"); ?>


WeatherUnderground 5-day Forecast - Saratoga, CA, USA

WeatherUnderground 5-day Forecast: Saratoga, CA, USA
Tomorrow Sunday Monday Tuesday Wednesday
Sunny Mostly Sunny Partly Cloudy Sunny Sunny
Sunny Mostly Sunny Partly Cloudy Sunny Sunny
88°F 87°F 85°F 92°F 93°F
UV: 7
UV: 7
UV: 7
UV: 7
UV: 7
Tonight Tomorrow night Sunday night Monday night Tuesday night Wednesday night
Clear Clear Mostly Clear Clear Clear Clear
Clear Clear Mostly Clear Clear Clear Clear
57°F 60°F 58°F 61°F 66°F 61°F


Clear skies. Low 57F. Winds light and variable.
Sunny. High 88F. Winds N at 10 to 20 mph.
Tomorrow night
Clear skies. Low around 60F. NW winds shifting to SSE at 10 to 15 mph.
Generally sunny despite a few afternoon clouds. High 87F. ENE winds shifting to NNW at 10 to 15 mph.
Sunday night
Clear to partly cloudy. Low 58F. Winds NW at 10 to 15 mph.
Partly cloudy skies. High near 85F. Winds NNW at 10 to 20 mph.
Monday night
A mostly clear sky. Low 61F. Winds N at 10 to 15 mph.
Sunny. High 92F. Winds N at 10 to 15 mph.
Tuesday night
Clear. Low 66F. Winds NNE at 5 to 10 mph.
Abundant sunshine. High 93F. Winds N at 10 to 15 mph.
Wednesday night
Clear skies. Low 61F. Winds SSW at 5 to 10 mph.


WeatherUnderground forecast for Saratoga, CA, USA.

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

$doPrintWC = false;
require("WC-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>$WCforecasticons[0]</td><td>$WCforecasticons[1]</td>\n"; ?>
<tr align="center" valign="top">
<?php print "<td>$WCforecasttemp[0]</td><td>$WCforecasttemp[1]</td>\n"; ?>

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\">$WCforecasticons[0]<br />$WCforecasttemp[0]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$WCforecasttext[0]</td>\n"; ?>
<tr valign="top">
<?php print "<td align=\"center\">$WCforecasticons[1]<br />$WCforecasttemp[1]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$WCforecasttext[1]</td>\n"; ?>

Clear skies. Low 57F. Winds light and variable.
Sunny. High 88F. Winds N at 10 to 20 mph.

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

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

Installation of WC-forecast.php

Download WC-forecast.php from the link below.

Optionally, download the Icon set, and upload to /forecast/images directory.

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

Download: WC-forecast.php (ML Version 1.04 - 22-Mar-2019 )

Demo: WC-forecast.php

Download: Icon Set (upload to your website in the /forecast/images directory)
This is the same icon set used in the Saratoga Base-World/Base-USA Template set.

Version history

  • Version 1.04 - 22-Mar-2019 - fix TWC/WU JSON degree sign \xc2\xba to correct UTF-8 \xc2\xb0
  • Version 1.03 - 10-Mar-2019 - added displays for all available icons in day-over-night mode
  • Version 1.02 - 04-Mar-2019 - rewrote icon printing for clairity and Day-over-Night display option
  • Version 1.01 - 02-Mar-2019 - corrected some WU variable names to WC variable names (missed in initial release :( )
  • Version 1.00 - 28-Feb-2019 - initial release