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 232327

Area Forecast Discussion
National Weather Service San Francisco Bay Area
427 PM PDT Sun Sep 23 2018

.SYNOPSIS...High pressure will begin to build over the region
through the first part of the week and result in a warming, drying
trend. This will will bring dry offshore winds at times and
increased fire weather concerns, especially for the North Bay
Hills tonight into Tuesday. Temperatures are forecast to cool late
in the week with the potential for unsettled weather conditions
during the upcoming weekend.

&& of 01:50 PM PDT Sunday...Breezy onshore flow
early this afternoon has allowed for cool conditions to prevail at
the coast despite the lack of cloud cover. Only low clouds/patchy
fog being reported is along Highway 1 from Monterey up to the
Aptos area and along the southern Big Sur Coastline. With
temperatures in the 50s and 60s at the coast, inland areas have
already warmed into the 70s and 80s for the most part. Looking the
rest of today to feel very Autumn like with a few degrees of
additional warming under a mainly clear sky.

As the passing mid/upper level short-wave trough shifts inland
tonight, upper level ridging will begin to build off of the Pacific
Northwest Coast and over northern California. This will allow for
weak offshore flow to develop over the interior and in the higher
elevations across the region ushering in a warmer, drier air mass.
Meanwhile, a weak marine layer is likely to persist along the coast
and allow for some stratus to return along coastal areas. The
warming and drying conditions will be most noted in the next 12 to
48 hours in the hills/higher elevations of the North and East Bay
regions which will result in near critical fire weather conditions.
Additional information can be found in the Fire Weather Discussion

The ridge of high pressure will continue to build through late week
with weak offshore flow at times. This will allow for the interior
to see afternoon temperatures back into the 80s and 90s by Wednesday
with coastal locations in the 70s to lower 80s (locations such as
Santa Cruz). By midweek, the marine layer may also become well mixed
enough to prevent widespread stratus develop during the overnight
and early morning hours. While daytime temperatures will warm to
above seasonal averages, overnight lows will be allowed to cool
decently given the long autumn nights. Thus, heat risks will remain
low to moderate for just about all major urban areas.

A Rex Block mid/upper level pattern is forecast to develop well off
of the West Coast late in the week as an upper level low begins to
undercut the ridge of high pressure. As this occurs, the air mass
aloft will begin to cool and allow for a cooling trend across the
region Thursday into Friday with an increase in onshore winds. The
marine layer may also rebound and allow for low level clouds to
return to the coast late in the week. Both the GFS and ECMWF
generate some precipitation at least across northern California and
as far south as the North Bay. Confidence remains low at this time
for any measurable precipitation, at least for any widespread
rainfall. However, the models do hint at a continued cool, unsettled
pattern over the region heading into the first of October. Something
we will need to keep an eye on in the coming days.


.AVIATION...As of 04:27 PM PDT Sunday...For 00z tafs. Satellite
imagery showing mainly clear skies across the region with some
passing high clouds. VFR through the evening with patchy IFR cigs
around the SF and Monterey Bay area taf sites tonight. Patchy
dense fog will possible in the early morning in the North Bay and
around the Monterey Bay. Onshore winds will diminish in the
overnight hours before picking up again tomorrow afternoon.

Low confidence on timing and extent of stratus redevelopment.

Vicinity of KSFO...VFR. Gusty winds will continue into the early
evening. May see some brief low cigs in the early morning.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR through the early evening. Early
return of low cigs tonight, with patchy dense fog developing late
tonight into early tomorrow morning.


.FIRE WEATHER...As of 10:00 AM PDT Sunday...The Fire Weather
Watch has been cancelled for the North Bay Mountains which was
previously in effect from 11 PM tonight through Tuesday afternoon.
However, dry northerly winds remain forecast to develop over this
region, especially over Napa County, during this timeframe. This
will drive humidity levels lower through Tuesday afternoon with
overnight recoveries only in the 20-25% range. Afternoon humidity
values may fall into the single digits to lower teens Monday and
Tuesday, yet wind speeds are forecast to remain below Red Flag

Precautions should still be taken as fuels remain critically dry
and any localized gusty winds in the ridges/peaks could result
in an elevated fire weather risk.

&& of 01:46 PM PDT Sunday...Moderate, locally gusty
northwest winds across the coastal waters through the remainder of
the day, especially north of Point Reyes and south of Point Sur
as well as in the outer waters. Locally steep fresh swell will be
generated by these gusty winds. Winds subside by tomorrow morning
through the coming days.


     .Tday...SCA...SF Bay
             SCA...Mry Bay
             SCA...Pigeon Pt to Pt Pinos 0-10 nm
             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 Saturday, September 22, 2018

High Temperature

107°F at Abilene/Muni, TX
107°F at El Centro Naf, CA

Low Temperature

25°F at Big Piney Amos, WY

High Precipatation

3.83in at Shreveport/Rgnl, LA

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