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 Tuesday, 27-Feb-2018 1:47 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 180523

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1023 PM PDT Sat Mar 17 2018

.SYNOPSIS...Showers will end in all areas by late evening. Expect
a cool night tonight with low temperatures in the 30s in most
valleys. Patchy dense fog may develop late tonight and persist
into Sunday morning. Dry weather, along with a warming trend, is
forecast from Sunday into Monday ahead of the next storm system.
The next system will bring widespread rainfall to our region from
Tuesday through Thursday, along with the potential for heavy rain
and locally strong southerly winds.


.DISCUSSION...As of 9:05 PM PDT Saturday...Our weather has
settled down this evening after an active day that included
isolated thunderstorms, rotating storms over the coastal waters,
and numerous reports of small hail. Shower activity rapidly
decreased late in the day as surface heating diminished. Current
radar shows almost no returns and expect precipitation to end in
all areas by late evening.

Skies have been clearing since sunset and temperatures have
already cooled into the mid 40s across inland areas. Primary
concern in the short term is how low temperatures will drop
overnight and whether freezing temperatures may occur by sunrise
Sunday. Surface dewpoints are currently in the lower 40s in most
areas and the WRF model indicates only marginal low level drying
overnight. This low level moisture should help keep temperatures
from dropping to freezing in most areas and it`s likely that we
will see patchy dense fog develop by late tonight. Forecast
overnight lows tonight mostly range from the mid 30s to mid 40s,
although a few of the colder inland locations may drop briefly to
near freezing around sunrise. In these areas we may see some
patchy freezing fog which could make for slippery roadways early
on Sunday.

The upper trough that brought our region several days of showery
weather will move well off to our east by tomorrow and a shortwave
ridge will develop over California. This ridge will result in
modest warming on Sunday along with dry conditions. Continued dry
weather along with more significant warming is expected on Monday
when the ridge over California amplifies downstream of a
deepening storm system well offshore.

The storm that will develop offshore early next week is expected
to tap into subtropical moisture. A plume of very moist air with
precipitable water values in excess of 1.5 inches is forecast to
begin arriving over California by Tuesday. Warm advection along
with orographic forcing is expected to begin generating widespread
rainfall across California on Tuesday. The GFS has been rather
consistent in initially focusing the moisture plume over south-
central California which would mean heaviest rain on Tuesday would
be from Monterey County southward. However, the 00Z NAM shows
rather uniform precipitation intensity across our forecast area on
Tuesday, which is similar to the 12Z ECMWF. Thus, there continues
to be uncertainty regarding the location of heaviest rainfall.
The upper trough is forecast to approach the coast on Wednesday
and Wednesday evening and this is when heavier rain rates will
likely be more widespread across our area, and also when southerly
winds will be strongest. Widespread rain is expected to change to
showers by Thursday morning (GFS) or Thursday evening (ECMWF) as
the trough moves inland. Needless to say there are still a lot of
details with this system that need to be sorted out, but the
overall message here is that most of California should be
prepared for potentially heavy precipitation and windy conditions
during the middle portion of next week.

&& of 10:35 PM PDT Saturday...Showers have diminished
rapidly leaving just a few clouds this evening. Low level
moisture remains near the surface which will allow for MVFR cigs
to develop around the SFO Bay Area after 12Z.

Vicinity of KSFO...Possible MVFR cigs after 12Z. Any cigs that
develop will be patchy in nature and should burn off after 16Z.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Some low clouds remain along the coastal
range which will keep brief MVFR cigs to MRY through 08Z. Drainage
wind will clear out the clouds after 08Z. Otherwise VFR.

&& of 10:15 PM PDT Saturday...Weak high pressure off the
California coast will bring light northwest winds through Sunday.
Winds will shift to southerly on Sunday night and increase Monday
and Tuesday as a deep low tracks northeast across the offshore
waters. Gale force winds or gusts is possible Tuesday with large
mixed swells.





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 Friday, March 16, 2018

High Temperature

93°F at Mcallen/Miller Intl, TX

Low Temperature

-7°F at Mount Washington, NH

High Precipatation

1.67in at Pine Belt Rgnl Awos, MS

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.03 - 13-Oct-2016 see history).