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

Buy Me A Coffee 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.

Note: Twitter widget has been disabled 3-Jul-2023 since it no longer displays the recent update Tweets.

This page was updated Tuesday, 28-Jul-2020 2:45 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 280952

Area Forecast Discussion
National Weather Service San Francisco CA
252 AM PDT Thu Sep 28 2023


Issued at 243 AM PDT Thu Sep 28 2023

Seasonable temperatures and breezy onshore winds expected today.
Rain is looking more probable across the area Friday into
Saturday with expected accumulations generally less than 0.25".
Warmer and drier conditions return briefly by midweek next week.


(Today and tonight)
Issued at 243 AM PDT Thu Sep 28 2023

Marine layer inversion is redeveloping early this morning under more
stable conditions. 500 mb temps will continue to warm through the
day today, which will bring warmer, near seasonable daytime temps
across the area. Max temps this afternoon will be a few degrees
warmer compared to Wednesday across the interior. Expecting
another round of breezy onshore winds with locally gusty
conditions near the coast/coastal gaps.


(Friday through Wednesday)
Issued at 243 AM PDT Thu Sep 28 2023

Upper low is on track to dig southward across the West Coast
Friday into Saturday as ridging across the E Pacific becomes more
amplified. Guidance continues to support a more westerly track as
this low digs south, resulting in wetter conditions and onshore
flow for our area. Confidence is increasing on widespread precip
chances. Over the last 24 hours, QPF and PoPs have trended higher
with widespread 30-50% PoPs in the forecast. Fri-Sat forecasted
rainfall amounts range from a few hundredths of an inch across the
North Bay to 0.3" over favored terrain across the Central Coast.
NBM has a 20-40% chance that the Bay Area and Central Coast get at
least 0.10" with highest chances across the Santa Cruz Mtns,
Diablo Range, and Santa Lucias.

In addition to rain chances, cooler air aloft from this deep low
will help to destabilize air Saturday morning, which has introduced
the slight chance of wet thunderstorms to the official forecast for
southern portions of the cwa. Stronger W/NW flow aloft, MUCAPE ~100-
300 J/Kg, and a passing vort max will favor highest chances for
storms (still low at 15%) across southern Monterey and San Benito
Counties early Sat. Post-frontal showers are possible Sunday
morning, but lower confidence for that scenario.

High pressure from the E Pacific will move east early to midweek
next week as upper low treks into the Great Basin, which will
prompt warmer and drier conditions by midweek.


(06Z TAFS)
Issued at 1046 PM PDT Wed Sep 27 2023

VFR continues through much of the TAF period for most terminals. The
one exception to this is Monterey Bay who is expected to develop
MVFR CIGs towards midnight. Otherwise, clear conditions prevail with
winds weakening into the night for most terminals. Winds increase
into the afternoon of Thursday to become onshore and breezy around
10-14 knots, and locally gusty near the SF Bay terminals.

Vicinity of SFO... VFR through the TAF period. Onshore winds have
begun to weaken but look to remain slightly elevated around 5-10
knots overnight. Though, gusty onshore winds similar to those seen
today return into the late afternoon of Thursday.

SFO Bridge Approach...Similar to SFO.

Monterey Bay Terminals...VFR conditions turn to become MVFR towards
midnight, with clearing to VFR expected again towards 15Z, though
low clouds may linger. Winds weak in the overnight hours this
morning, then increasing into the afternoon to become breezy around
12 knots.


(Today through Tuesday)
Issued at 243 AM PDT Thu Sep 28 2023

Northwesterly winds continue to strengthen, with gales beginning
to develop over much of the outer waters and coastal jet regions.
Gales last through much of the day today, then weakening towards
late Friday morning to become fresh. Northwest swell continues to
diminish, though large wind waves build overnight tonight and
persist through the weekend. Both winds and waves will combine to
create dangerous conditions for small craft through the remainder
of the week. Chances of rain approach towards Saturday evening
with the arrival of a new low pressure system.


PZ...Small Craft Advisory until 3 AM PDT early this morning for

     Small Craft Advisory from 3 PM this afternoon to 9 PM PDT this
     evening for PZZ535.

     Small Craft Advisory until 3 PM PDT this afternoon for PZZ540-

     Gale Warning from 3 PM this afternoon to 3 AM PDT Friday for

     Small Craft Advisory until 3 AM PDT Friday for PZZ545.

     Gale Warning from 3 PM this afternoon to 9 PM PDT this evening
     for PZZ560.

     Gale Warning until 9 AM PDT Friday for PZZ565.

     Gale Warning until 3 AM PDT Friday for PZZ570-575.



LONG TERM....McCorkle

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 World Extremes

This script was originated by Michael of and has been rewritten to use the NWS Climate Prediction Center's CSV file for world observations. 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 variables:

$omittedCountry (text list of countries excluded from $world high/low/precip scans)
Note: the setting $ignoreCountrys is the array of country names to to exclude

$selectedCountry (setting: country name for selected country high/low/precip)
Note: run to see the list of country names to use

$usahigh (Note: for lower-48 USA states)
$usalow (Note: for lower-48 USA states)
$usaprecip (Note: for lower-48 USA states)

$selectedState (setting: USA state 2-character name abbreviation in settings area)
$selectState (a copy of $selectedState for compatibility with old stateextremes.php)

$reportDate (nicely formatted date of the report)
$stateReportDate (a copy of $reportDate for compatibility with old stateextremes.php)

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 courtesy of <a href=\"";
print "";
print "\">NWS-CPC</a></small></p>\n";


which produces this result (with live data):

USA Extremes for Tuesday, September 26, 2023

High Temperature

105°F at Phoenix Airport, AZ

Low Temperature

24°F at Mammoth Lakes Mammoth Yosemite Ap, CA

High Precipatation

6.14in at Brunswick-mckinnon Arpt, GA

Data courtesy 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.

$cacheFileDir = './'; // directory to store cache file in.
$cacheFile2 = "worldextremesCache.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 (display in C is default)
$rUOM = 'in';     // or ='' for no rain unit display (display in mm is default)
$ignoreCountrys = array('Antarctica','Greenland');     // for world extremes - exclude these country(s)
$ignoreStations = array('99KLRJ');     // list of stn_id (field 0) to ignore for bogus data
$tempDiffAllowed = 40; // max difference Tmax-Tmin (C) for valid data
$selectedCountry = 'Canada'; // for country max/min/precip in $country* variables
// note: the $usa* variables will have the min/max/precip for the lower-48 states
$selectedState   = 'CA';  // for USA state max/min/precip in $state* variables

Note that $cacheFileDir, $tUOM, $rUOM will use the Saratoga template Settings.php values if used in a Saratoga template.

NWS CPC One Day Extremes PHP script Download (5.04 - 28-Jul-2020 see history).