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 240537

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1037 PM PDT Fri Mar 23 2018

.SYNOPSIS...A cold front will spread rain from north to south
across much of the region tonight and Saturday morning. Additional
shower activity is forecast Saturday late afternoon and evening
with isolated showers possibly lingering into Sunday. Dry weather
is expected to return on Monday and continue through next week. A
warming trend is forecast for the first half of the week.


.DISCUSSION...As of 8:55 PM PDT Friday...Satellite, radar, and
observations indicate that the cold front approaching from the
northwest is currently near Point Arena. Based on the latest HRRR
model, expect the cold front to spread rain across the North Bay
between about 10 pm and 2 am, then south across the rest of the SF
Bay Area between 2 am and 5 am Saturday, and finally through the
Monterey Bay Area between 5 am and 8 am. Several lightning strikes
have been detected along the northern California coast north of
Point Arena this evening, so a slight chance of thunderstorms have
been added to the North Bay for later this evening.

All of the models indicate little or no precipitation following
the front on Saturday until the cold upper low approaches late in
the day. Thus, most of Saturday may end up being dry under partly
cloudy skies. The evening forecast update included a reduction in
shower chances for most of Saturday.

Shower chances will increase late Saturday afternoon and evening
as the cold upper trough approaches the northern California coast.
Based on the 00Z models, shower chances will spread into our
forecast area from late Saturday afternoon into Saturday night.
But rainfall then is not expected to be as widespread as with the
cold front moving through tonight. There is also a slight chance
of thunderstorms late Saturday afternoon and early evening, mainly
across the North Bay where instability will be greatest.

Isolated showers may linger into Sunday, mainly near the coast in
the morning, and then along the eastern portion of our forecast
area in the afternoon. But for the most part Sunday is expected to
be a dry and cool day.

This incoming system will not have a whole lot of moisture to work
with and so rain totals from tonight through the weekend are
forecast to generally be a half inch or less, with highest amounts
in the North Bay. Some southern inland areas may see little, if
any, rainfall.

Snow levels will start off around 3500 feet tonight, but then drop
as low as 2500 feet by Saturday and Saturday night. Since the bulk
of the precipitation is expected to fall with the cold front
tonight and prior to the arrival of the coldest air, only light
snowfall accumulation is expected on the higher peaks.

Models continue to indicate dry weather through next week, along
with a warming trend, as a ridge of high pressure develops
offshore and then slowly moves eastward.


.AVIATION...As of 10:37 PM PDT Friday...for 06Z Saturday TAFs.
GOES-East water vapor imagery a boundary approaching the North Bay
at this time. Radar shows some light to moderate rain showers
already making their way into Sonoma and Marin Counties. Light
rain has been observed at KSTS as of the 06Z TAF publishing time.
The boundary will push south and bring mostly VFR/MVFR conditions
to San Francisco Bay Area terminals overnight and into early
Saturday. Expect VFR conditions to subsequently prevail post-

Vicinity of KSFO...VFR conditions expected for the next several
hours ahead of the approaching front. Increasing clouds associated
with the front will bring some BKN/OVC clouds around 3,000 ft
around/after 08Z Saturday, as well as the chance of light rain.
Expect VFR conditions to then return sometime around/after 12-15Z
Saturday. West winds are forecast post-frontal, with wind speeds
around 15 kt (and possibly higher) on Saturday afternoon.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR conditions expected for another
several hours before the cold front brings increasing low clouds
to KSNS and KMRY. During this time, will likely see MVFR/VRF
ceilings. Rain chances will also increase during the frontal


.MARINE...As of 8:16 PM PDT Friday...Lightning strikes have been
observed off the Northern California coast near Fort Bragg.
There`s a slight chances of thunderstorms across the northern
waters over the next few hours. Light to moderate west to
southwest winds will prevail as a cold front makes its way through
the coastal waters late tonight. Light rain is possible along the
front, and winds will turn northwesterly in its wake. A second
cold front is expected Saturday evening into Sunday morning.
Northwest swell will increase slightly overnight tonight.


     .Tday...SCA...Pt Arena to Pt Reyes 0-10 nm
             SCA...Pt Arena to Pigeon Pt 10-60 nm
             SCA...SF Bay until 3 AM
             SCA...Pt Reyes to Pigeon Pt 0-10 nm until 3 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 Thursday, March 22, 2018

High Temperature

92°F at Ft Stockton, TX
92°F at Wink/Winkler Co, TX

Low Temperature

-2°F at Grand Marais/Cook Cnty, MN

High Precipatation

3.75in at Blue Canyon Amos, CA

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