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, 10-Feb-2019 7:10 PM

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 281228

Area Forecast Discussion
National Weather Service San Francisco Bay Area
428 AM PST Tue Jan 28 2020

.SYNOPSIS...Light rain will be possible over the North Bay and as
far south as San Francisco through early afternoon. Dry conditions
are then forecast region-wide through the remainder of the week
along with a gradual warming trend. Cooling is then forecast by
Sunday and into early next week.

&& of 02:58 AM PST Tuesday...A mid/upper level
system approaching the Pacific Northwest has pushed a frontal
boundary into Northern California early this morning. Ahead of the
boundary, high level clouds continue to advect inland while low
level moisture in the boundary layer has also resulted in low
clouds over much of the region. This cloud cover has kept
temperatures generally in the upper 40s to lower 50s so far this

Light rain associated with the front is being detected by regional
radar over Northern California and as far south as Mendocino County.
This will continue to advance inland and southward through the
morning with light precipitation likely to develop over the North
Bay around sunrise and then continue through mid-morning. Light rain
may push as far south as San Francisco and the San Mateo coastline
before dissipating by early afternoon. Thus, most areas to the south
of the aforementioned areas will remain dry today. Areas that do
receive rainfall will generally see amounts of one-tenth of an inch
or less.

A warming trend will occur through the remainder of the week as high
pressure over the eastern Pacific builds inland. With 850 mb
temperatures forecast to approach 15 deg C by Friday and Saturday,
look for daytime temperatures to be 5 to 10 degrees above seasonal
averages. Widespread middle/upper 60s are likely with lower 70s
across the interior. Cannot even rule out maximum temperatures
reaching into the middle 70s by Sunday afternoon under mainly clear
sky conditions.

Temperatures cool region-wide by Sunday and into early next week as
the ridge is replaced by a broad mid/upper level trough. However,
precipitation will likely remain to the north and east of the
region. Longer range outlooks maintain dry weather conditions over
much of the region through early February.

&& of 4:28 AM PST Tuesday...For 12Z TAFs... A weak
frontal boundary will move over the Bay Area and Monterey Bay
regions through the day today. This will bring some light rain to
many of the terminals in the Bay Area proper and maybe some brief
light rain in Monterey. Winds around the front are not forecast to
be of any significance either. Behind the front, when the winds
shift to come out of the northwest, there may be a brief period
when the winds pick up to 10 knots or so, but otherwise they are
forecast to remain weak. Tonight into Wednesday morning will be
the difficult part. High pressure building across the area in the
wake of the front will help to trap some of the low level moisture
in the area which could yield some low cigs and vsby issues at
some terminals tonight. The TAFs continue to hint at this
possibility with STS being the near sure bet of low cigs and vsby

Vicinity of KSFO...MVFR is starting the morning at SFO and is
expected to continue through much of the day as a weak frontal
boundary limps through the area. In the wake of the front,
residual moisture and building high pressure may cause overnight
lowering cigs and vsby. Something that will need to be watched for
development. Think of summer type conditions.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Some passing low cigs in the area this
morning are forecast to mix out as a weakening frontal boundary
approaches. As the front limps over the area more low cigs are
likely. High pressure will build in the wake of the dissipating
front, which will cause possible reduction in vsby at Monterey
terminal tonight. This will need watching.

&& of 04:11 AM PST Tuesday...A weak cool front moving
across the coastal waters this morning will give way to increasing
winds from the north and building short period seas. Conditions
will remain elevated through the work week. A Long period
northwest swell will arrive later this week.


     .Tday...SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 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 USA Extremes

This script was originated by Michael of and has been rewritten to use the NWS Climate Prediction Center's One Day Old Daily Data Summary text file for the USA. 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 four variables:

$usahigh - contains the text of the high temperature station(s) (value and station name from the NWS)
$usalow - contains the text of the low temperature station(s) (value and station name from the NWS)
$usaprecip - contains the text of the high precipitation station(s) (value and station name from the NWS)
$reportDate - contains the text of the date for the report (default format is 'Dayname, Month day, Year')

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 courtsey of <a href=\"";
print "";
print "\">NWS-CPC</a></small></p>\n";


which produces this result (with live data):

USA Extremes for Monday, January 27, 2020

High Temperature

126°F at Winona Muni (awos), MN

Low Temperature

-8°F at Grand Forks/Intl, ND

High Precipatation

1.50in at Astoria/Clatsop Co, OR

Data courtsey 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.

// Site to Parse
$url2 = "";
// Name of cache file  --  This file must be set to CHMOD-666
$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "usaextremesCache4.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
$rUOM = 'in';     // or ='' for no rain unit display
$ignoreStations = array('99NRB'); // Station numbers to ignore, Array of station numbers

NWS CPC One Day Extremes PHP script Download (4.03e - 09-Feb-2019 see history).