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 150527

Area Forecast Discussion
National Weather Service San Francisco Bay Area
927 PM PST Wed Nov 14 2018

.SYNOPSIS...Smoke and haze continue to impact much of the Bay Area
while dry and seasonable weather persists elsewhere. No big
changes in the weather through the end of the work week with some
signs of less smoke and slightly cooler temperatures over the
weekend. Dry conditions persist at least through Tuesday with
possible pattern change by the middle of next week.

&& of 08:50 PM PST Wednesday...The biggest impact
to the Bay Area this since this afternoon continues to be focused
on smoke and its impacts. There was a wind shift through the
Delta late this afternoon leading to a deluge of smoke into San
Francisco Bay and portions of the East Bay. It was so bad the
webcams had a hard time showing the sunset with visibility sensors
at 3/4 of a mile. Once the smoke made its way west it eventually
pushed southward into the Santa Clara Valley as well. The San Jose
Airport dropped down to 2 1/2 miles vis. Lastly, air quality
stations took a nose dive during this timeframe to the very
unhealthy category for some areas. Needless to say smoke continues
to adversely impact the region. Unfortunately, now that sun has
set and the atmosphere is becoming more stable smoke will remain
tonight. The early frames from the 00Z HRRR smoke model confirm
this thinking with smoke lingering around San Francisco Bay. No
updates are planned for the overnight period. One potential area
that may be an issue are overnight lows. This morning`s low were
pretty chilly across the interior valleys. Model guidance has
trended slightly warmer for tonight, but would not be surprised if
a few protect valleys drop into the mid to lower 30s.

Now for the extended forecast - a giant question mark, well at
least for timing and details. Model run consistency and consensus
has not been that great. GFS keeps flip flopping from wet to dry
and vice versa. The ECMWF has been slightly more consistent, but
not great. Keep in mind the forecast period having trouble is
toward the end of the model run and confidence is usually pretty
low that far out. For what it`s worth the 00Z GFS is in and keeps
the Bay Area dry through Thanksgiving and finally brings rain next


.PREV of 2:56 PM PST Wednesday...Smoke from the Camp
Fire continues to be one of the main impacts on Bay Area weather.
Satellite showed another belch of smoke this morning that has
worked its way down the Sac Valley and into the Bay Area.
Gradients show a half millibar offshore from Sac to SFO with east
winds blowing in the Delta and bringing the smoke westward into
the Bay Area. Visibility is now less than a mile in Livermore with
the East Bay indicating some of the poorest visibility. Hazy
skies continue elsewhere with afternoon highs generally in the 60s
with 70s for the Central Coast. Very dry conditions continue this
afternoon with many sites reporting humidity values in the single
digits including usually wet spots such as Big Sur coming in at

Day over day changes in the large scale weather remain minor with
daytime highs in the 60s and 70s with fairly cool overnight lows
from the mid 30s to mid 40s through the end of the work week.
Million dollar question is how active the Camp Fire will burn the
next few days. As was shown today with lighter winds and even
light offshore flow the smoke will tend to drift towards the Bay
Area until we get a shift in the large scale weather patterns.

That may occur by this weekend as an upper low approaches the
Southern California coast and some type of southerly flow may help
to keep any smoke to our east. It should be noted that latest
trends build a ridge over northeast California over the weekend
that will keep warm and dry weather up there with a fairly strong
low level inversion likely in place, not ideal for smoke

Long range forecast details regarding any rainfall next week
continues to be watched. The 12 and 18z gfs deterministic runs
have been discouraging and gone completely dry. Need to note that
the ensembles still show a trough along the west coast Weds
through Friday of next week. The ecmwf has a weak front on Weds
and a second stronger storm by about next Friday. This is all
still 7-10 days out so confidence remains low on details as we
anxiously await a pattern shift. Until then mild and dry weather
for at least another 6 days.


.AVIATION...As of 09:27 PM PST Wednesday...For 06Z TAFs. Smoke
continues to be an issue with reduced visibilities still being
reported across area terminals. Mainly MVFR vis with isolated
instances of IFR. Latest smoke model forecast does not indicate
that this will change overnight. Expect reduced vis at the surface
as well as slant range vis issues to persist due to smoke. Winds
will remain generally light through the period.

Vicinity of KSFO...MVFR vis due to smoke with generally light
winds. Slant range vis issues expected to persist. Latest HRRR
smoke forecast does not suggest much change in smoke conditions
through at least tonight.

SFO Bridge Approach...Similar to terminal.

Monterey Bay Terminals...VFR prevailing with periods of reduced
vis to MVFR due to smoke.

&& of 08:14 PM PST Wednesday...Generally light north to
northwest winds will continue across the coastal waters through
the end of the week and into the coming weekend. Expect locally
breezy winds near coastal gaps and favored coastal jet locations
during the afternoon and evening hours. Light mixed swell will
persist before a new northwest swell arrives tomorrow.





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 Tuesday, November 13, 2018

High Temperature

90°F at Winter Haven, FL

Low Temperature

-10°F at Bemidji Municipal, MN
-10°F at Hibbing/Chisholm, MN

High Precipatation

4.16in at Hatteras (asos), 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).