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 230557

Area Forecast Discussion
National Weather Service San Francisco Bay Area
957 PM PST Wed Jan 22 2020

.SYNOPSIS...Mainly dry weather conditions along with a gradual
warming trend is expected through Friday. A weak storm system moving
into Northern California will bring a chance of precipitation to
the region this upcoming weekend.

&& of 9:10 PM PST Wednesday...Temperatures finished
off on average 3 to 6 degrees warmer across the board today with
some locations in the warmer inland areas seeing upward of 11
degrees of warming. Temperatures reached mid 50s to mid 60s under
the influence of a building trough despite patchy morning fog and
a slow clearing this morning.

Mostly clear skies persist across the region at this hour with a
few high clouds streaming across the sky. Lingering low level
moisture and light winds will once again lead to patchy low
clouds and fog overnight. Satellite imagery depicts low clouds
already developing along the Big Sur coast as well as advecting
into the eastern portions of Alameda, Santa Clara, and San Benito
counties from the Central Valley.

From previous discussion...Mainly dry weather conditions will
persist through late week with a gradual warming trend region-
wide. Will likely see more widespread 60s during the afternoon
hours by Thursday, Friday and potentially Saturday as high
pressure builds over the region. Cannot even rule out a few of the
warmer interior locations of the Central Coast approaching 70s
deg F late this week. The only chance of precipitation late in the
week will be over northern Sonoma County late Thursday into
Friday when a system passes inland to the north. Regardless,
widespread precipitation is not likely.

The next chance of widespread rainfall is forecast for this upcoming
weekend when a mid/upper level trough pushes into the Pacific
Northwest. This will drag a frontal boundary into the North Bay
sometime around Friday night before moving southward through the
weekend. While this system looks to bring some precipitation to much
of the region, widespread heavy rainfall is unlikely. Additionally,
impacts from this system will be minimal with mostly beneficial
rainfall. Temperatures will also cool late in the weekend into early
next week in response to the upper level trough. Precipitation
chances diminish early next week for much of the region as weak
ridging builds back into place. However, unsettled conditions are
likely to persist over northern California through at least the
first half of next week as systems push inland. This may allow for
some light rainfall over the North Bay, but again widespread impacts
are unlikely.

&& of 09:55 PM PST Wednesday...For 06z TAFs. Skies
are mostly clear with a few high clouds passing overhead this
evening. Near surface moisture remains elevated and patchy low
cloud and fog development will be a concern tonight through
Thursday morning. Fog is most likely across the North Bay
overnight. Have maintained mention of low clouds and reduced vis
across the Bay Area terminals in the tafs but confidence remains
low. High clouds will increase and thicken late tonight. Any fog
which forms tonight will clear by Thursday afternoon, with VFR
during the afternoon hours. Winds will generally be light through
the period.

Vicinity of KSFO...VFR expected through 12z with passing high
clouds. Low clouds and patchy fog may develop after 12z, however
exact timing and coverage remain lower confidence. Patchy haze and
reduced vis will be possible through 21z Thursday, otherwise VFR
Thursday afternoon and evening. Winds will be light through the
period. A weak boundary late in the period will bring increased
low-level moisture and low clouds late Thursday night.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Comms issues continue with Salinas ASOS
and FAA lines. VFR expected late this evening with patchy low
clouds and fog returning early Thursday morning. Exact timing and
coverage remain lower confidence. Light offshore winds through
Thursday morning with onshore winds Thursday afternoon.

&& of 8:57 PM PST Wednesday...Seas will continue to
decrease overnight into Thursday with light winds over the waters.
Generally light winds will persist Friday and Saturday with high
pressure over the region. However a long period northwest swell
will pass through the waters Friday and Saturday. The next storm
approaches later Saturday into Sunday with increasing southerly
winds followed by another large northwest swell behind the front
Sunday into Monday.




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 Tuesday, January 21, 2020

High Temperature

83°F at Roosevelt Roads Nas, PU

Low Temperature

-24°F at Clayton Lake, ME

High Precipatation

1.37in at Bremerton Ntnl Awos, WA

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).