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 222052

Area Forecast Discussion
National Weather Service San Francisco Bay Area
152 PM PDT Tue Aug 22 2017

.SYNOPSIS...Dry weather will prevail today with temperatures
near to slightly below normal for the middle of August. Low
clouds and fog will persist in the overnight and early morning
near the coast and in the valleys the next several days. An inland
warming trend is likely late in the week and into the upcoming
weekend due to strengthening high pressure.

&& of 1:51 PM PDT Tuesday...This morning`s overcast
conditions over most of the San Francisco Bay Area have
transitioned to a mostly clear afternoon for much of the area. Low
clouds are still lingering from Point Reys northward as well as
the Monterey Peninsula. When all is set and done this afternoon,
high temperatures should generally top out in the 60s and low 70s
along the coast and upper 70s to perhaps the low 90s for interior
locations. Expect the warmest locations to be in interior San
Benito and Monterey Counties with mid 90s likely.

Synoptically an upper level low remains centered around 150 miles
offshore from Big Sur around 35N 124W. Models advertise this low
to push onshore by midweek as a broader longwave trough approaches
coastal British Columbia. Not expecting much day-to-day change in
temperatures for any particular location during this time with
high temperatures running near seasonal normals. This changes for
Friday as models show a ridge beginning to build over the Four
Corners and expanding west over the weekend. Interior areas will
return back to the 90s and 100s as a result. Long range guidance
suggests the ridge will remain parked over the Southwest with
above normal temperatures likely continuing into next week.


.AVIATION...As of 10:50 AM PDT Tuesday...For 18z TAFs. Surface
high off the Central Coast mitigated impact of overnight marine
layer, with IFR TO MVFR cigs focused primarily over the San
Francisco Bay area. Cigs have retreated offshore/mixed out with
only a few thin layers of stratus left over the Bay Bridge
corridor between downtown San Francisco and Oakland. Look for
breezy afternoon winds and a later return of a shallower marine
layer tonight.

Vicinity of KSFO...VFR today. Light to moderate west winds will
prevail this afternoon, sustained 12-17 kt, with occasional gusts
possible. Borderline IFR-MVFR SCT-BKN late tonight into sunrise

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR today. Surface high offshore kept
marine clouds at bay (in the bay) overnight, however, look for
LIFR to IFR cigs later tonight. Light winds will pick up out of
the west/northwest this afternoon, 9-13 kt.

&& of 01:46 PM PDT Tuesday...Light to moderate winds
through midweek, with locally stronger winds through coastal gaps
during the afternoons. Building high pressure from the west will
bring stronger northerly winds and steep fresh swell. No
significant long period swell through the upcoming week.


     .Tngt...SCA...SF Bay until 9 PM




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 Monday, August 21, 2017

High Temperature

107°F at Palm Springs Rgnl, CA
107°F at Thermal, CA

Low Temperature

35°F at Stanley Ranger Stn, ID

High Precipatation

4.06in at Kansas City/Intl, MO

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