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 Sunday, 05-Apr-2020 7:47 AM

PHP for NWS Area Forecast Discussion

This PHP script will fetch and cache the Forecast Area Discussion issued by your local NWS office.
Thanks to Mike Challis of Long Beach, WA for the inspiration for and enhancement of this script.

FXUS66 KMTR 080602

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1102 PM PDT Tue Apr 7 2020

.SYNOPSIS...Isolated to scattered rain showers will be possible over
the Central Coast through midweek while mainly dry conditions
prevail to the north. Temperatures will begin a gradual warming
trend late in the week and into the upcoming weekend as conditions
dry out region-wide.

&& of 9:00 PM PDT Tuesday...Satellite imagery show
a large swath of high clouds advecting northward across Monterey
and San Benito counties at this hour. These clouds will continue
to traverse across the region overnight as they wrap around a low
pressure system, currently centered off the Southern California
coast. Not only will these high clouds make it hard to see the
Supermoon-Pink Moon tonight, they are making it hard to see what
is happening at the surface or if any showers are moving into the
area. Doppler radar has not shown any returns over the southern
portion of the forecast area and there have been no tips in the
rain gages so far. Latest runs of our high resolution models have
slowed the onset of rain in the area with latest projections
showing showers moving in after 06z tonight. This coincides with
the change in trajectory of the low toward the Southern
California coast. Models keep most of the precip south of the
Monterey Bay tonight and Wednesday however a stray shower cannot
be ruled out farther north as moisture continues to wraps around
the low.

The forecast remains on track. No updates expected this evening.

From previous discussion...Isolated to potentially scattered
showers will remain possible over the southern portion of the
region again on Wednesday and potentially into Thursday as the
mid/upper level low off of the central and southern California
coast slowly approaches the coast. This will also allow for
seasonably cool conditions to persist over the southern areas
while places such as the North Bay begin to experience a gradual
warming trend through midweek. Mostly dry conditions will also
prevail over the northern portion of the region through midweek.

The aforementioned mid/upper level low will push inland over
southern California late in the week with conditions beginning to
dry out region-wide. As it shifts inland this weekend, a warming
trend is likely with more widespread mid/upper 60s near the coast
and low/mid 70s over the interior. This trend is likely to extend
into early next week as an upper level ridge builds just off of the
West Coast.

&& of 10:55 PM PDT Tuesday...Humidities in the North
and East Bay are running 15-20 percent drier than yesterday which
reduces the chances for fog tonight.

Satellite image shows mid level clouds approaching the Bay Area
from the south while low clouds are luking over the waters. Models
still showing moist northwest flow bringing MVFR cigs into the SFO
and MRY Bay Area by 12Z and hanging around through early

Vicinity of KSFO...Mid level clouds after 09Z. MVFR cigs after 12Z
with bases around 2500 ft. Becoming scattered clouds after 21Z.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Mid level clouds. Any precip should stay
to the south. MVFR cigs after 12Z.

&& of 10:47 PM PDT Tuesday...Northwest winds will
decrease on Wednesday as a low pressure system over southern
California moves further inland. A long  period southwest will mix
with a long period west to northwest  swell through the week.


     .Tngt...SCA...Pigeon Pt to Pt Pinos 0-10 nm until 3 AM
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm until 3 AM
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pt Arena to Pt Reyes 0-10 nm




Visit us at

Follow us on Facebook, Twitter, and YouTube at:

NWS MTR Office Area Forecast Discussion

To use, include the output of the script on your webpage by using

$doIncludeFD = true;
include("forecast-discussion.php"); ?>

to perform the include. Settings inside the script are:

// settings:
//  change myNWS to abbreviation for your local NWS office
//    other settings are optional
    $myNWS = 'MTR';   // San Francisco, NWS office
//  $myNWS = 'PQR';   // Portland, OR
//  $myNWS = 'OAX';   // Omaha, NE (Carter Lake, IA)
$cacheName = "forecast-discussion.txt"; // used to store the file so we don't have to // fetch it each time $refetchSeconds = 1800; // refetch every nnnn seconds
$cacheFileDir = './'; // default cache file directory // end of settings

The only required setting is for $myNWS which designates the local NWS office.
To find the 3-character abbreviation for your local NWS office for the $myNWS variable, follow these steps:

  1. Browse to
  2. Use the search box on the left to search for your city, state
  3. Look at the URL in the 'Forecast Discussion' link near the bottom of the page
  4. Use the 3-character abbreviation is in the &issuedby=XXX parameter on the Forecast Discussion link (XXX will be your local office)
  5. put the XXX in the $myNWS = 'XXX'; statement

The script has two optional parameters when you call it by URL from your website::

Will return the contents without the surrounding <html><head></head><body> and </body></html> tags
Will override the default $refetchSeconds=1800 so that the cache is refreshed immediately

NWS Area Forecast Discussion PHP script Demo and Download (1.06 - 27-Feb-2018 see history).

PHP for NWS CPC World Extremes

This script was originated by Michael of and has been rewritten to use the NWS Climate Prediction Center's CSV file for world observations. The script does not produce output (other than HTML comments for status), so you are free to include it in a page, and format the text output as you desire. The script returns data in variables:

$omittedCountry (text list of countries excluded from $world high/low/precip scans)
Note: the setting $ignoreCountrys is the array of country names to to exclude

$selectedCountry (setting: country name for selected country high/low/precip)
Note: run to see the list of country names to use

$usahigh (Note: for lower-48 USA states)
$usalow (Note: for lower-48 USA states)
$usaprecip (Note: for lower-48 USA states)

$selectedState (setting: USA state 2-character name abbreviation in settings area)
$selectState (a copy of $selectedState for compatibility with old stateextremes.php)

$reportDate (nicely formatted date of the report)
$stateReportDate (a copy of $reportDate for compatibility with old stateextremes.php)

You can run the script by using:


print "<p>USA Extremes for $reportDate</p>\n";
print "<p>High Temperature<br/><br/>$usahigh</p>\n";
print "<p>Low Temperature<br/><br/>$usalow</p>\n";
print "<p>High Precipatation<br/><br/>$usaprecip</p>\n";
print "<p><small>Data courtesy of <a href=\"";
print "";
print "\">NWS-CPC</a></small></p>\n";


which produces this result (with live data):

USA Extremes for Monday, April 6, 2020

High Temperature

89°F at Miami/Kendall-tamiami, FL

Low Temperature

14°F at Eielson Afb, AK
14°F at Port Heiden (amos), AK
14°F at Meridian/Key Field, MS

High Precipatation

1.67in at Van Nuys Airport, CA

Data courtesy of NWS-CPC

The script has internal settings which you can adjust. If run in a Saratoga template, the cache file will be stored in the ./cache/ directory based on $SITE['cacheFileDir'] in Settings.php.

$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "worldextremesCache.txt";  
// Age of cache file before re-fetch caching time, in seconds (3600 = 1 hour)
$cache_life = '3600';
$reportDateFormat = "l, F j, Y"; // Day, Month d, yyyy 
$tUOM = '&deg;F'; // or ='' for no temperature unit display (display in C is default)
$rUOM = 'in';     // or ='' for no rain unit display (display in mm is default)
$ignoreCountrys = array('Antarctica','Greenland');     // for world extremes - exclude these country(s)
$tempDiffAllowed = 40; // max difference Tmax-Tmin (C) for valid data
$selectedCountry = 'Canada'; // for country max/min/precip in $country* variables
// note: the $usa* variables will have the min/max/precip for the lower-48 states
$selectedState   = 'CA';  // for USA state max/min/precip in $state* variables

Note that $cacheFileDir, $tUOM, $rUOM will use the Saratoga template Settings.php values if used in a Saratoga template.

NWS CPC One Day Extremes PHP script Download (5.01 - 05-Apr-2020 see history).