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 252021

Area Forecast Discussion
National Weather Service San Francisco Bay Area
121 PM PDT Tue Apr 25 2017

.SYNOPSIS...Seasonably cool temperatures will persist into
Wednesday as a weak system passes inland to the north. This will
result in a slight chance of light precipitation, mainly from the
Santa Cruz Mountains northward into Wednesday. A warming and
drying trend will then get underway beginning Thursday and likely
continuing into the upcoming weekend as high pressure builds over
the eastern Pacific. Breezy northerly winds are also possible from
Thursday into Friday, especially in the hills.

&& of 01:20 PM PDT Tuesday...Deep moisture aloft
continues to advect inland across the region this afternoon and
has resulted in widespread mid/high level cloudiness. All of this
is in advance of a weak mid/upper level trough that will push
inland into the Pacific Northwest late tonight into Wednesday.
This system may bring some very light precipitation to the
northern portion of our region, mainly from the Santa Cruz
Mountains northward early Wednesday morning. Cannot rule out some
lingering showers into the early afternoon from the East Bay Hills
down into the Santa Lucia Mountains, yet chances for widespread
measurable rainfall remain minimal as this system lacks needed
mid/upper level support as it pushes inland to our north. With
this passing system, temperatures will be seasonably cool and
temperatures will range from the lower 06s coast to middle 60s
inland through Wednesday. Some of the warmer, interior locations
of the Central Coast may warm into the lower 70s.

A warming trend will then get underway by Thursday as dry conditions
return along with mostly sunny skies. As a stronger mid/upper level
low drops southward out of Canada into the Rockies and high pressure
develops offshore late in the week, temperatures will warm into the
70s inland. In addition, breezy to locally gusty winds will develop
due to the tightening pressure gradient from Thursday into Friday.
Further warming of the air mass aloft will result in lower 80s
during the afternoon hours this weekend while onshore winds near the
coast keep temperatures in the 60s to 70s.

Temperatures moderate slightly by early next week as the mid/upper
level ridge weakens as a system pushes inland into the Pacific
Northwest. With that said, the main storm track will remain well
north of the region and dry weather conditions are likely into the
beginning of May.

&& of 10:19 AM PDT Tuesday...Mid and high level clouds
continue to stream in from the north ahead of the next system.
Expecting VFR today with breezy conditions. Cigs will gradually
lower overnight with -ra poss at KSTS early Wed, but will only do

Vicinity of KSFO...Little change from previous forecast. VFR
through today. MVFR cigs develop tonight/early Wednesday. A
passing shower poss early Wednesday.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Afternoon sea breeze. Lower cigs
return tonight with MVFR category.

&& of 10:17 AM PDT Tuesday...Moderate to locally strong
northerly winds will prevail as high pressure remains anchored off
the coast. The strongest winds will likely occur monterey bay
southward along the immediate coast. Winds and seas will increase
over all coastal waters on Wednesday as high pressure


     .Tngt...SCA...Mry Bay until 9 PM
             SCA...Pigeon Pt to Pt Pinos 0-10 nm until 9 PM
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm




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 Monday, April 24, 2017

High Temperature

98°F at Wink/Winkler Co, TX

Low Temperature

23°F at Yellowstone (ramos), WY

High Precipatation

4.80in at Raleigh-durham, NC

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