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 220559

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1057 PM PDT Sat Oct 21 2017

.SYNOPSIS...The warming trend that got underway across our region
today will continue tomorrow. The warming trend will intensify on
Monday when offshore flow strengthens. Very warm and dry
conditions are forecast across the region on both Monday and
Tuesday. Dry weather conditions will persist through next week.
Gradual cooling if forecast during the second half of the week,
but temperatures will remain above seasonal averages.


.DISCUSSION...As of 8:40 PM PDT Saturday...An upper ridge began
to strengthen over California today and onshore flow weakened. The
result was warmer temperatures today. Today`s highs were
generally 5 to 10 degrees warmer compared to Friday, but still a
couple of degrees cooler than normal in most areas. Today will be
the last day of cooler than average temperatures for quite some

Expect another 5 to 10 degrees of warming on Sunday as the upper
ridge continues to build along the West Coast. The warming and
drying trend across our region will then intensify on Monday
after offshore flow develops on Sunday night. North to northeast
winds are expected to strengthen in our hills late Sunday night
and Monday morning. Strongest winds are forecast to be at the
higher elevations of the North Bay where local gusts up to 40 mph
are likely. Locally gusty winds are also likely elsewhere,
especially in the East Bay Hills and higher elevations of the
Santa Cruz Mountains. Winds will not likely be strong enough to
meet wind advisory criteria, but gusty winds and a drier airmass
will begin to raise fire weather concerns by Monday (see Fire
Weather Discussion below for details).

High temperatures on Monday and Tuesday are forecast to be in the
80s and lower 90s across our entire region. Tuesday is expected to
be the warmest day of the week when a few mid 90s are possible.
While these warm temperatures will increase heat risks locally
into the moderate category by Tuesday, the long and relatively
cool late October nights will help to mitigate heat risks
associated with the very warm days.

The upper ridge is forecast to weaken and retreat offshore around
midweek which will result in slight cooling during the second half
of next week. In any case, expect continued dry weather and warmer
than normal temperatures through the end of the week. Longer range
models show no rain in site through the end of the month.


.AVIATION...As of 10:57 PM PDT Saturday...VFR continues over most
of the Bay Area and north Central Coast tonight and Sunday. Dewpoint
temperatures are higher per 24 hour trends coupled with radiative
cooling under mainly clear skies tonight and early Sunday morning
may produce a patch or two of valley fog. Low clouds as well as
some patchy fog will linger along coastal Sonoma county to the San
Mateo coast into Sunday morning. A very strong late October ridge
develops Sunday through Tuesday. The ACV-SFO pressure gradient nears
5 mb late Sunday into Monday and the WMC-SFO gradient increases to
10-13 mb Sunday night into Monday; there is potential for low level
wind shear later Sunday evening into Monday morning at KOAK, KLVK,

Vicinity of KSFO...VFR. Light west wind tonight, W-NW wind increasing
to 15-20 knots Sunday afternoon and evening. Low level wind shear
06z-12z Monday.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...VFR. Light and variable late this evening
possibly becoming light SE very early Sunday morning. Onshore winds
10-20 knots Sunday afternoon then mainly light E-SE drainage wind
flow begins Sunday evening, possibly becoming gusty overnight in
the Salinas Valley.


.FIRE WEATHER...As of 8:30 PM PDT Saturday...Gradual warming and
drying will continue across the district into Sunday. Then,
offshore flow is forecast to strengthen on Sunday night, resulting
in much warmer and drier conditions by Monday. Locally moderate
and gusty north to northeast winds are forecast in the hills late
Sunday night and Monday morning, particularly at the higher
elevations of the North Bay, but also locally in the East Bay
Hills and Santa Cruz Mountains. Wind gusts of between 25 and 35
mph are likely in these locations late Sunday night and Monday
morning, with local gusts in excess of 40 mph possible across the
higher ridges of the North Bay. In addition, nighttime humidity
recoveries will be poor in the hills on Sunday night. Were it not
for the recent wetting rains on Thursday night, these developments
would have resulted in critical fire weather conditions. However,
finer fuels are expected to retain enough moisture in the short
term to mitigate fire weather concerns to some extent. But fuels
will dry out quickly early in the week under these conditions.
Another round of gusty winds in the hills is expected Monday night
into Tuesday morning, especially in the North Bay Hills. While
winds on Monday night are not expected to be as strong as on
Sunday night, winds on Monday night may be of greater concern as
fuels will have had longer to dry by then. Will continue to
monitor fuel moisture over the next few days and issue Red Flag
Warnings if warranted. Winds are expected to subside in all areas
by Tuesday afternoon, but very warm and dry conditions will
continue through midweek. Slight cooling is expected Wednesday and
Thursday as high pressure over California weakens.

&& of 10:37 PM PDT Saturday...Northwesterly winds are
gusty over the southernmost waters this evening while winds are
lighter elsewhere. Northwesterly winds will gradually increase
over the remaining coastal waters Sunday and Sunday night.
Northwest swell periods will decrease slowly through late Sunday,
however, hazardous conditions due to squared seas will exist in
most offshore areas through tonight.


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




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 Friday, October 20, 2017

High Temperature

93°F at Carroll, IA

Low Temperature

22°F at Big Piney Amos, WY

High Precipatation

1.81in at Houston/Clover Field, 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).