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 141712

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1012 AM PDT Tue Aug 14 2018

.SYNOPSIS...Temperatures will be near to slightly below seasonal
averages through midweek as a modest marine layer and onshore flow
persist over the region. High pressure is then forecast to rebuild
toward the West Coast late in the week and into next week bringing
warmer temperatures to the interior.

&& of 09:10 AM PDT Tuesday...Satellite imagery this
morning shows extensive cloud cover for this time of year with a
marine layer at around 1,500 feet in depth. Thus, low clouds
spread well inland into just about all valley locations overnight
with patchy drizzle reported along many coastal areas as well as
into the East Bay Hills. Aloft, high level clouds can be seen as
well as mid/upper level moisture advects northward over the
region. Any convection at this time appears to be across the
interior portion of the state. Given the cloud cover, have lowered
temperatures by a few degrees for locations around the greater
San Francisco Bay Area. Otherwise, the rest of the forecast
appears on track this morning. For additional details, please see
the previous forecast discussion below.


.PREV of 3:41 AM PDT Tuesday...Average temperatures
Monday were a couple to a few degrees below August 13 normals at
the coast, around the bays, and inland. Sea surface temperatures
at the buoys are presently 54 to 56 (except Half Moon Bay`s 59 SST
appears a bit mild in comparison. Half Moon Bay`s morning lows
back through August 1st have been chillier than the buoy`s sea sfc
temp) At any rate onshore breezes continue this morning, it`s
chilliest ocean side along with patches of drizzle while mostly
cloudy skies extend well inland from the coast. Clearing back to
near the immediate coast will return by afternoon. Onshore breezes
will help keep daytime temperatures tempered at or below normal
maximum temperatures today and likely again Wednesday.

A warming trend will commence later in the week as the high pressure
center over the southwestern U.S. eventually returns and rebuilds
over California. Temperatures will then warm back up to normal to
a few degrees above mid August normals with 80s/90s maybe 100 degree
mark inland, but sea-breezes should keep seasonably cool temperatures
going along the coast, over the weekend.

&& of 10:12 AM PDT Tuesday...for 18Z TAF package.
Widespread stratus continues to impact the area this morning with
MVFR/IFR ceilings reported at some point at all TAF sites. GOES-
East visible shows that the stratus pushed well inland, up to the
Pacheco Pass along the Santa Clara/Merced County line. Expect late
clearing compared to usual at the terminals today, with some
locations possibly remaining overcast into the afternoon hours.

Vicinity of KSFO...MVFR/IFR ceilings are expected to continue for
the next few hours, associated with a deep marine layer, before
transitioning back to VFR. The latest TAF package brings the
return of the stratus several hours earlier based on current
trends and guidance.

SFO Bridge Approach...Similar to the terminal.

Monterey Bay Terminals...MVFR/IFR ceilings expected for much of
the morning at both KSNS and KMRY. Could be one of those events
with KMRY maintaining overcast skies all day. Expect ceilings to
drop again in the evening hours and after sunset with IFR
conditions into Wednesday morning.

&& of 09:10 AM PDT Tuesday...Light to locally moderate
winds will continue this afternoon over the coastal waters. The
northwest swell is forecast to remain light to moderate this week,
while the southerly swell will gradually increase through the
week and into the weekend.


     .Tday...SCA...SF Bay from 2 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.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 Monday, August 13, 2018

High Temperature

111°F at Needles Airport, CA

Low Temperature

34°F at Meacham Amos, OR

High Precipatation

5.64in at Belmar-farmdale, NJ

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