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 222013

Area Forecast Discussion
National Weather Service San Francisco Bay Area
113 PM PDT Mon May 22 2017

.SYNOPSIS...Look for cooler conditions through most of the week as
a onshore flow combines with the marine layer. Minor warming is
then expected during the upcoming weekend especially for inland


.DISCUSSION...As of 1:15 PM PDT Monday...As expected temperatures
are running cooler for all locations away from the coast today
with many spots 5 to 12 degrees less than values from Sunday.
Current readings show a wide range from 50s and 60s to parts of
the coast with 70s and 80s inland. Still a few hours of heating,
so would expect the warmest inland spots to again get into the
90s, however the number of locations should be less than
yesterday. Satellite shows widespread clouds along the water and
with the minor onshore flow expected to continue, likely that many
of the local beaches will see little to no sunshine today.
Tonight will be a near repeat of last night with patchy fog along
the coast and to some inland spots. Lows will mostly be in the 50s
with 60s above 1500 feet.

Synoptically the ridge of high pressure in charge will begin to
flatten out through the week as a system dives down from Canada
and works into the Northern Rockies. 500 MB heights will drop from
587 DM today to 573 DM by Thursday. Inland locations that have
been in the 90s the past few days will drop back into the upper
60s to the lower 70s. Closer to the coast widespread mid 50s to
mid 60s can be expected. With the onshore flow in place, much of
the week could by quite grey at the coast.

Longer range guidance shows the ridge trying to rebuild by the
weekend although heights will be less than the past few days. By
Sunday inland spots will be back in the mid 70s to mid 80s away
from the coast with 60s to mid 70s near the water.


.AVIATION...As of 10:26 AM PDT Monday...For 18z tafs. Shallow
marine layer is eroding back to the coast as 18Z tafs become
valid. VFR at all terminals this afternoon with breezy sea breeze
conditions this afternoon. Shallow marine layer will return
tonight with fog possible.

Vicinity of KSFO...VFR through early tonight. Based on latest
model guidance and what happened this morning will bring low
clouds back into SF Bay. The low confidence area will once again
be SFO itself. Went with a pessimistic forecast tonight with a few
hours of clouds/fog tomorrow before a quick burn off.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR this afternoon. Cigs return this
evening with IFR to LIFR conditions possible.

&& of 10:23 AM PDT Monday...High pressure building over
the Pacific Northwest will maintain light to moderate
northwesterly winds through midweek. Winds will increase midweek
as a thermal trough develops along the coast tightening the
pressure gradients over the northern outer waters. Strongest winds
are expected over the outer waters while the inner waters remain
mostly light.


     .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 Sunday, May 21, 2017

High Temperature

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

Low Temperature

17°F at Leadville, CO

High Precipatation

3.19in at Del Rio/Intl, TX

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