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 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 201552

Area Forecast Discussion
National Weather Service San Francisco Bay Area
852 AM PDT Sat Apr 20 2019

.SYNOPSIS...A passing cold front will bring cooler weather and
coastal drizzle to the Bay Area Saturday. Warmer weather is
forecast on Sunday with building high pressure. A more noticeable
warming trend will develop early next week with above normal

&& of 08:46 AM PDT Saturday...A quick moving frontal
boundary bisects the region at this hour with breezy to locally
gusty northwest winds developing in wake of its passage. The very
moist boundary layer ahead of the front resulted in widespread
drizzle with many locations reporting trace amounts to a few
hundredths of an inch near the coast and across the greater San
Francisco Bay Area. Look for cooler temperatures, breezy winds,
and partly to mostly cloudy conditions to prevail through the
remainder of the day. With this said, the ongoing forecast remains
on track with no updates anticipated at this time. For additional
information, please see the forecast discussion below.


.PREV of 03:03 AM PDT Saturday...A much deeper
marine layer is currently impacting the Bay Area ahead of an
approaching cold front. Ft Ord puts the depth near 1,800-2,000
feet this morning. Satellite imagery shows another night of
widespread coastal and inland valley stratus. Automated sensors
around the region also indicate some patchy fog with visibility
three to six miles and at times less. Additionally, Half Moon Bay
reported a few hours of -RA and drizzle has been observed here at
the forecast office. A few other sites around the region tipped
0.01" of precip this morning too. Needless to say, but a very
moist boundary layer is present this morning. Current forecast
will continue the mention of morning clouds, fog and drizzle. As
for the cold front itself, latest surface analysis puts the front
near the far Northern Sonoma county. KMUX radar imagery actually
shows a few echoes off the coast, which is likely the front. Not
expecting much precip from the front, but more drizzle from the
very moist low levels. The cold front is projected to move through
the Bay Area today, which will result in cool and cloudy
conditions. Forecast highs today will be in the upper 50s to mid
60s at the coast and 60s to lower 70s inland or several degrees
below normal.

A few low clouds will be possible tonight with some lingering
drizzle, especially Monterey/Big Sur area, as the front exits to
the east. By Sunday high pressure will begin to build over the
region which will kick off a noticeable warming and drying trend.
Temperatures on Sunday will warm three to six degrees. High
pressure will continue to build into next week and peak
Tuesday/Wednesday. Unlike the last warm up this warm up will have
some offshore flow support. Latest WRF model indicates decent NE
winds at 925mb Monday and Tuesday. Offshore flow will erode any
remaining stratus and introduce lower RH values, especially
overnight across the N and E Bay Hills. The strength of the ridge
is projected to be two to three standard deviations above normal
at 500 mb. Simply put, much above normal for this time of year
resulting in some rather warm temperatures. By Wednesday,
interior portions of Monterey/San Benito could see temperatures
in the mid 90s. Other locations around the Bay Area will not be as
warm, but 70-80s around the Bay Shoreline and widespread 80s
inland. Both Tuesday and Wednesday will see high temperatures as
much as 15 degrees above normal.

Very subtle cooling on Thursday as flow aloft become more zonal
and low level flow becomes more onshore. A bigger drop in
temperatures is forecast on Friday and next weekend as an upper
level low moves toward the PacNW. Unlike previous model runs the
GFS has now backed off on precip chances next weekend and is more
inline with the ECMWF.

&& of 5:03 AM PDT Saturday...Ongoing onshore push of
stratus ramps up through morning per recent statistical guidance
forecasting increasing southwest to west winds by late morning and
afternoon. Metar observations range from IFR in patchy drizzle or
light rain to MVFR-VFR. LIFR probability satellite imagery shows
plenty of coastal stratus and fog converging along the coastline
and extending inland. Incoming cold front later today sweeps SE
over the area with potential for strong and gusty post frontal
winds over a large part of the area this afternoon and evening.
Winds will shift to west to northwest and leaving few-sct cloud
coverage at lower levels, in general VFR returns late today and
tonight as well as for Sunday.

Vicinity of KSFO...W-SW wind 10 to 15 knots becoming W by late
morning and increasingly strong and gusty with gusts up over 30
knots in the afternoon and evening. Ceiling lifts quickly to
MVFR-VFR by late morning.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Patchy drizzle or light rain in IFR
ceilings this morning, ceilings then lifting to MVFR by late
morning. Gusty winds developing in the afternoon. VFR tonight and

&& of 08:46 AM PDT Saturday...A cold front is sweeping
through the waters from north to south this morning. Gusty
northwest winds will prevail across the waters as a result today.
Occasional gale force gusts are possible late this morning
through the afternoon. These gusty winds will generate steep fresh
swell which is hazardous for small craft vessels. Moderate
northwest swell.


     .Tday...SCA...Pigeon Pt to Pt Pinos 0-10 nm from 9 AM
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm from 9 AM
             SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Reyes to Pigeon Pt 0-10 nm
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...SF Bay from 9 AM
             SCA...Mry Bay from 9 AM




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, April 19, 2019

High Temperature

101°F at Thermal, CA

Low Temperature

21°F at Crane Lake (awos), MN
21°F at Ely Muni (awos), MN
21°F at Phillips/Price Co., WI

High Precipatation

5.29in at Asheville/Muni, NC

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