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 Thursday, 13-Oct-2016 12:40 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 261022

Area Forecast Discussion
National Weather Service San Francisco Bay Area
322 AM PDT Sun Mar 26 2017

.SYNOPSIS...A weak weather system will spread light rain across
the North Bay this afternoon and across most of the remainder of
the forecast area this evening and overnight. Showers will mostly
end by Monday morning. Expect decreasing clouds on Monday with
brisk afternoon and evening northwest winds. High pressure will
then produce dry weather through midweek, along with a warming
trend. Shower chances will return to northern and eastern portions
of our region Wednesday night and Thursday as a weather system
drops inland to our east. Temporary cooling and blustery
conditions are also expected with this system.


.DISCUSSION...As of 3:20 AM PDT Sunday...High clouds have been
increasing overnight as a weak weather system approaches from the
west-northwest. The models have slowed the arrival of
precipitation with this system, with rain now expected to develop
only in the North Bay between midday and late afternoon. Most
areas south and east of San Francisco will probably remain dry
through late afternoon. Light rain is then expected to develop
over most of the remainder of our forecast area during the evening
hours. Rainfall totals through tonight are forecast to range from
0.10-0.40" in the North Bay, with totals mostly under a tenth of
an inch for all other areas.

A few showers may linger into Monday morning, but for the most
part Monday should be a dry day as the system departs quickly to
the southeast and a high pressure ridge builds just offshore.
Brisk northwest winds are likely by Monday afternoon with
strongest winds expected near the coast where local gusts up to 35
mph are possible late Monday afternoon and early evening.

The upper ridge offshore is forecast to build inland over
California on Tuesday and Wednesday, bringing dry weather along
with a warming trend. High temperatures by Wednesday are forecast
to be mostly in the upper 60s and 70s.

The GFS and ECMWF have come into better agreement regarding a
system that will impact our area shortly after midweek. Both
models show a system dropping in from the northwest and across far
northern California on Wednesday night, and then proceeding into
the Great Basin by Thursday. This system will be an `inside
slider` which will mean that most, if not all, precipitation will
be confined to areas to our north and east - which is what the
GFS is forecasting. However, the past two runs of the ECMWF have
forecast precipitation farther to the south and east and into our
area. Have therefore added shower chances across the northern and
eastern portions of our area for Wednesday Night and Thursday. A
cooler airmass will arrive with this system on Thursday and high
temperatures may cool by as much as 10 degrees from Wednesday to
Thursday. In addition, potentially quite strong and gusty north to
northwest winds will develop on Thursday and continue into
Thursday Night. Locally blustery conditions may then continue in
the hills into Friday night as well. If conditions develop as
currently forecast by the models, wind advisories may be needed
for portions of our forecast area later in the week.

Warming and drying will occur late in the week and into next
weekend as an upper ridge once again builds across California.


.AVIATION...As of 10:42 PM PDT Saturday...A few locations along
the immediate coastline are reporting MVFR cigs this evening
otherwise it`s VFR. Winds remain onshore through tonight the
pressure gradient then becoming near neutral SFO-SAC on Sunday.
Light rain with the next weather system reaches the North Bay
beginning late Sunday morning, light rain spreads southeast over
the remainder of the area through Sunday afternoon and evening.

Vicinity of KSFO...VFR. Tempo MVFR cig 11z-15z Sunday. Light rain is
predicted to begin early Sunday evening.

SFO Bridge Approach...Same as KSFO.

Monterey Bay Terminals...VFR. Onshore winds becoming light and variable
late tonight then southerly on Sunday. Light rain likely beginning
mid-late Sunday evening.

&& of 10:24 PM PDT Saturday...Generally light winds and
moderate seas across the waters through tonight. Gusty winds along
the inner waters south of Point Sur will diminish through tonight.
On Sunday, winds over the waters will increase and turn southerly
as a weak cold front approaches.


     .Tday...SCA...Pt Arena to Pigeon Pt 10-60 nm from 9 AM



MARINE: Anna/Canepa

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.05 - 31-Mar-2015 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 24, 2017

High Temperature

91°F at Mcallen/Miller Intl, TX

Low Temperature

-6°F at Clayton Lake, ME

High Precipatation

2.24in at Burlington (asos), CO

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