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.

Many of these scripts are now available on GitHub at

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 Sunday, 10-Feb-2019 7:10 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 251205

Area Forecast Discussion
National Weather Service San Francisco Bay Area
405 AM PST Sat Jan 25 2020

.SYNOPSIS...Some patchy dense valley fog this morning otherwise
increasing clouds through the day as a warm front approaches.
Light rain will develop in the North Bay late this afternoon into
this evening. Then a cold front will pass through the Bay Area
overnight with some light rain into early Sunday morning. Dry
weather returns midday Sunday into Monday. Another weak front by
Tuesday brings more light rain chances to the North Bay but dry
from the Golden Gate southward. Long range trends look seasonably
warm and dry as high pressure builds.

&& of 2:21 AM PST Saturday...Short term concern
this morning will be areas of dense fog through sunrise. Salinas
already down to 1/4 mile fog in the Salinas Valley with Santa Rosa
at 3/4 mile in the North Bay. Dewpoints remain high in the upper
40s and lower 50s keeping the airmass pretty juicy. Synoptic
pattern features a weak warm front approaching today. Buoys are
reporting some light southerly winds with IR satellite showing
increasing mid and high clouds this afternoon. This will
eventually lead to some light rain across the North Bay late this
afternoon and evening as warm front moves onshore. Light rain
chances spread towards the Golden Gate this evening but rain
remains light and spotty. Overnight a cold front will then pass
over the region, keeping rain chances going in the North Bay with
scattered light rain throughout the Bay Area overnight. Rain
chances from San Jose southward to the Central Coast look slight
with any amounts being very light around sunrise Sunday as the
cold front passes through.

After a cool and damp start Sunday morning, by midday nice weather
returns as high pressure builds with highs back into the mid 50s
and lower 60s. Forecast for Monday is dry with near normal highs
after valley fog in the morning.

Another weak front may skirt the North Bay to the Golden Gate
Tuesday with some light rain chances.

Strong high pressure builds from midweek and beyond with plenty
of sunshine and highs likely peaking in the mid 60s with even some
70s for the Central Coast. Current models keep mild and dry
weather into next weekend with some hint of a colder (but dry)
trough by around Feb 3rd.

&& of 04:00 AM PST Saturday...For 12Z TAFs. Weak
surface boundaries will interact with the region over the course
of the TAF period, primarily impacting terminals by bringing
periods of LIFR-MVFR cigs/visbys and brief VCSH/-SHRA while winds
will be generally light (ie less than 10 kt). Early morning night
time microphysics satellite imagery shows pockets of dense fog (ie
1/4sm + VV002) at KSNS and a rather low cloud deck in the Bay
Area (cigs at 400-600 feet at KSTS/KSFO/KSJC). Fog bank evident
near KMRY as well but a brief period of southerly winds advected
the fog bank northward into the Marina area, however, winds have
turned light and fog/vcfg may return to KMRY by sunrise hours...
similar to yesterday morning. Poor conditions with abundant low to
mid level moisture will persist in the North Bay while improving
conditions with lifting/scattered cloud decks will occur
southward. Another round of poor overnight cigs/visbys will occur
tonight with a slight chance of very light showers through the
night with the next air mass boundary.

Vicinity of KSFO...Expanding low clouds near KSFO at or around
300-500 feet, however, deck is not robust and shifting winds are
pushing these clouds in and out of the vicinity of the terminal,
so expect evolving conditions through the morning with reductions
and visibility accompanying the low clouds. Models prog improving
conditions by very late morning to early afternoon, however, there
is a small chance models are overconfident and clouds linger
throughout the day (though not as thick as this morning). Low
clouds and reduced visbys will then reform by the late afternoon
to early evening with the next boundary. Highest chance of
showers looks to be around 09-14Z tomorrow night, though, they
will be weak. Winds generally light SE ahead of air mass
boundaries but could see it shift westerly during the afternoon.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Very similar scenario as yesterday
morning where low clouds/fog formed near KMRY but were blown out
of the terminal vicinity by weak S/SE winds. Meanwhile, a more
robust fog bank develops throughout the Salinas valley (incl at
KSNS) and into the Marina/Castroville area of the Monterey Bay.
Expect to see very poor conditions at KSNS persist while KMRY will
should remain in mostly clear (with vicinity fog) as long as the
light S/SE winds persist. KMRY may fill back in if winds cut off.
Clouds lift/thin by mid to late morning though should see
lingering FEW/SCT cloud decks in the 3000-5000 ft range as low to
mid level moisture remains abundant. An earlier return of IFR or
less cigs is possible by 00-02Z at the terminals ahead of the next

&& of 03:48 AM PST Saturday...Light split flow winds
through the early afternoon, with  increasing southerly winds in
the northern waters and weakening  northerly winds in the southern
waters. Winds shift to become south to southwest across the waters
by this evening ahead of a surface frontal boundary before
shifting to become northerly by  Sunday morning. A long period
west to northwest swell will  continue to impact the waters
through Saturday. This will create  conditions hazardous to small
crafts. Additional long period  northwest swells will arrive this
weekend and early next week.


     .Tday...SCA...Mry Bay until 3 PM
             SCA...Pt Arena to Pt Reyes 0-10 nm until 3 PM
             SCA...Pt Reyes to Pigeon Pt 0-10 nm until 3 PM
             SCA...Pigeon Pt to Pt Pinos 0-10 nm until 3 PM
             SCA...Pt Pinos to Pt Piedras Blancas 0-10 nm until 3 PM
             SCA...Pt Arena to Pigeon Pt 10-60 nm until 3 PM
             SCA...Pigeon Pt to Pt Piedras Blancas 10-60 nm until 3 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.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, January 23, 2020

High Temperature

83°F at Charlotte Amalie Virgi, IS

Low Temperature

-7°F at Berlin Municipal, NH

High Precipatation

4.09in at Quillayute/State, WA

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.03e - 09-Feb-2019 see history).