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.

Many of these scripts are now available on GitHub at

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 180003

Area Forecast Discussion
National Weather Service San Francisco Bay Area
503 PM PDT Thu Oct 17 2019

.SYNOPSIS...Cooler and breezy conditions are expected to develop
in wake of the frontal passage this afternoon and continue through
Saturday. A warming and drying trend will begin over the weekend
and continue into next week.

&& of 1:33 PM PDT Thursday...Skies have cleared
across the district except for a few cumulus clouds over far
northern Sonoma county. Current temperatures are warmer than
yesterday at this time by as many as 7 degrees with readings in
the 60s to lower 70s. The onshore surface pressure gradient has
tightened and westerly winds are starting to ramp up. SFO now at
17 kts, and San Jose gusting to 24 kts. Winds are expected to
decrease overnight, but remain breezy over the coastal waters and
near the coast. Similar conditions are expected on Friday, except
with less wind. Highs in the 60s near the coast with lower 70s
possible in the interior valleys.

Another weak weather system will move across the North Bay late
Friday night into Saturday morning. This system may produce a
brief period of light rain across mainly the North Bay, leaving
most of the remainder of the area dry. As this system moves to
the east, a brief period of dry offshore winds will be possible
over the North Bay by late Sunday night into early Monday.
However, these winds are not forecast to be strong. A subtle
warming trend is also expected by Sunday as high pressure builds
over the eastern Pacific.

This high pressure ridge is then forecast to rebuild into
California by the middle of next week. This will bring a warming
and drying trend, along with periods of offshore flow. Strongest
offshore winds could occur Tuesday night into Wednesday morning.
This combined with persistent dry conditions will require
monitoring for potential fire weather concerns.

&& of 5:00 PM PDT Thursday...The marine layer has
mixed out following the frontal passage. VFR conditions expected
all areas through Friday. Winds have been gusty with SFO seeing
peak gusts to near 35 kt and this will continue through tonight.

Vicinity of KSFO...VFR. West winds 25-30 kt gusting to near 35 kt
through 04Z. Winds decreasing to 15-20 kt gusting to 25 kt after

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Gusty west to northwest winds to
20-25 kt through 04Z.


.FIRE WEATHER...As of 02:12 PM PDT Thursday...Short term fire
weather concerns will be focused over the southern portion of the
district with weak to moderate offshore flow (NE winds at 925mb)
Friday night/early Saturday. Local WRF model highlights NE winds
over the Santa Lucia Mts with NE winds 25-35 mph with humidity
recovery pretty poor. Offshore flow weakens through the day on Saturday
with increasing RH. Longer term fire weather concerns then switch
large scale with more widespread offshore flow. Models build large
scale high pressure aloft over the region and EPAC. At the
surface, high pressure moves into the PacNW with low pressure
along the coast setting the stage for offshore. The peak offshore
period appears to be Tuesday night/Wednesday. The GFS shows a
SFO-WMC gradient of 14.9mb, which is pretty solid and would likely
result in a Fire Watch/Red Flag. A lot will change between now and
then, but something to keep an eye next Tuesday through Thursday.

&& of 04:54 PM PDT Thursday...A storm system over the
Gulf of Alaska will maintain moderate  northwest winds over the
waters through Friday. A large,  northwest swell generated by the
long fetch from this system   will arrive this afternoon with the
largest waves occurring  Thursday night and Friday. The northwest
swell will persist as the dominant wave through the weekend, waves
will slowly diminish  from their peak heights but will remain at
hazard levels for small craft.


     .Tngt...High Surf Advisory...CAZ006-505-509-529-530
             SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Reyes to Pigeon Pt 0-10 nm
             SCA...Pigeon Pt to Pt Pinos 0-10 nm
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm
             SCA...Rough Bar Advisory for SF Bar
             SCA...Mry Bay
             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.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 Wednesday, October 16, 2019

High Temperature

99°F at Thermal, CA

Low Temperature

16°F at Gunnison Co (awos), CO

High Precipatation

3.20in at Danbury Municipal, CT

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