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 231151

Area Forecast Discussion
National Weather Service San Francisco Bay Area
451 AM PDT Fri Jun 23 2017

.SYNOPSIS...Cooling trend starts today for most areas as onshore
flow returns. The far interior valleys will remain seasonably
warm through this evening. The overall trend this weekend and into
next week will be a return to more seasonable temperatures along
with more extensive night and morning low clouds followed by sunny

&& of 3:34 AM PDT Friday...All signs point to a
significant cooling trend today and for the coastal valleys these
transitions are rarely gradual. The marine layer has deepened to
around 1200 feet around Monterey Bay and trending deeper with a
southerly surface wind component as the southerly wind reversal is
now approaching Cape Mendocino. 24 hour trends for the hills show
as much as 10-20 degrees of cooling at this hour due to a
deepening marine layer and onshore winds. The gradients from
Arcata to SFO have gone flat while the SFO to Sac is 3.3 mb
onshore at this early hour. Wind out in the Delta are already
gusting to 25 kt as cooler marine air oozes inland. Given all
this will maintain the current heat advisories for some of the far
interior zones and hills. This is mainly being done for
consistency of message and lingering heat impacts for heat
sensitive populations. Its expected that any remaining heat
headlines for our office will be allowed to expire by 9 pm this
evening if not earlier.

Looking at the 06z nam graphical and mos output numbers confidence
is growing that the overall trend this weekend will be continued
cooling back to or even slightly below normal by Sunday afternoon.
In general it looks like a more normal summer time weather
pattern this weekend across the Bay Area with night and morning
low clouds pulling back to the coast and followed by clear and
warm afternoons.

Latest ecmwf keeps a zonal or slightly cyclonic flow aloft off the
coast for next week implying near normal temperatures with dry
weather forecast. Longer range solutions later next week or
towards the end of the month show more pronounced ridging with
potential for another round of weak offshore flow and associated


.AVIATION...As of 4:55 AM PDT Friday...For 12z Tafs. Compressed
but relatively deeper marine layer offshore pushing further
inland this morning bringing VLIFR-IFR cigs to low lying areas
along the coast this morning. Expect to see further expansion of
marine stratus/low clouds through the early morning hours before
retreating in the 17Z hour. Winds generally light today, except
breezy onshore winds through coastal gaps, including near KSFO, by
this afternoon and evening.

Vicinity of KSFO...Stratus in the Bay Area will need to wrap
clockwise around the Bay before reaching KSFO. More likely to see
low clouds near the bridge/KSMB rather than the tower/KSFO this
morning. Low confidence this morning with forecast counting on
VFR conditions at KSFO but possible impacts near bridge.

SFO Bridge Approach...Similar to KSFO with higher chance of LIFR-
IFR cigs at bridge versus tower.

Monterey Bay Terminals...VLIFR TO IFR cigs through 17Z hour. Early
return of low clouds/stratus tonight.  Generally light winds.

&& of 04:43 AM PDT Friday...Generally light southerly
winds over the coastal waters today. Onshore winds increase later
today and tonight through coastal  gaps such as the Golden Gate
gap and across the northern San Francisco Bay. Northwest winds
return this weekend. Generally decreasing seas through the coming


     .Tday...Heat Advisory...CAZ510-511-517-518 til 9 pm
             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.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 Thursday, June 22, 2017

High Temperature

119°F at Needles Airport, CA

Low Temperature

34°F at Meacham Amos, OR
34°F at Stanley Ranger Stn, ID

High Precipatation

2.74in at Tuscaloosa/Muni, AL

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