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 252127

Area Forecast Discussion
National Weather Service San Francisco CA
227 PM PDT Tue Jun 25 2024


Issued at 220 PM PDT Tue Jun 25 2024

Chances for elevated thunderstorms continue across the Bay Area
through this evening with chances diminishing by evening. Cooler,
seasonal to below average temperatures return Wednesday and
persist through the end of the week.


(This evening through Wednesday)
Issued at 220 PM PDT Tue Jun 25 2024

Slight (10-15%) chance of thunderstorms producing dry lightning
continues over the Bay Area before chances diminish by the late
evening. Radar continues to show elevated cells moving over
Sonoma, Napa, and Marin Counties with the potential for isolated
thunderstorms continuing into the evening hours. For lightning
activity so far today, several strikes occurred in the vicinity of
the San Jose and Livermore airports this morning. Three airports
(San Francisco, Livermore, and San Jose) observed trace
precipitation overnight and again this morning, indicating some
precipitation is making it to the surface. However, precipitation
totals greater than a few hundredths of an inch are not
anticipated as most precipitation is expected to evaporate before
reaching the ground (creating a neat phenomenon known as virga).
Remember to stay weather aware and when thunder roars, go indoors!

Tuesday continues to be the warmest day this week with temperatures
cooling down beginning Wednesday. Tonight`s overnight low
temperatures, both inland and along the coast, will range from the
low to upper 50`s. Upper level troughing will move inland tonight
into tomorrow with temperatures cooling down to seasonal to slightly
below average. Wednesday`s inland high temperatures are expected to
be 3 to 7 degrees cooler than today`s with most areas seeing highs
in the upper 70`s to mid 80`s. Favored inland hot spots may see
temperatures reach the upper 80`s. Closer to the coast, cooler
temperatures prevail with highs largely in the upper 50`s to mid
60`s. As upper level troughing moves inland, the marine layer is
expected to deepen with increasing stratus chances along the
coastline and portions of the San Francisco Bay.


(Wednesday night through next Monday)
Issued at 220 PM PDT Tue Jun 25 2024

Upper level troughing will persist through late week with seasonal
to below average temperatures similar to Wednesday (upper 70`s to
mid 80`s inland and upper 50`s to mid 60`s along the coast)
continuing through Saturday. However, by Sunday, guidance continues
to indicate a warming trend will develop as upper level ridging
again builds over the West Coast. While this forecast is several
days out and subject to revision, here is a preview of what the
warming trend currently looks like. By Sunday, inland temperatures
will gradually warm into the upper 80`s to low 90`s before reaching
into the low to mid 90`s on Monday and low to upper 90`s on Tuesday.
While outside of this forecast period, longer term guidance suggests
that these warmer temperatures will prevail through most of next
week. For those along the coast, temperatures will warm into the
60`s to low 70`s beginning Sunday through the end of the forecast


(18Z TAFS)
Issued at 1059 AM PDT Tue Jun 25 2024

High-level clouds with a few embedded storm cells are moving across
the region through the region. Chances for storms linger into the
evening but more of the focus will be to the north and east of the
region. Expect breezy conditions through the afternoon that ease into
the evening. As winds reduce, IFR/MVFR CIGs begin to move inland
affecting the Monterey Bay TAF sites this evening, with OAK and SFO
affected late into the night. Winds stay light to moderate through
Wednesday morning, with CIGs dissipating in the mid to late morning.
Expect widespread VFR by Wednesday afternoon with gusty and breezy

Vicinity of SFO...Broken high-level clouds become scattered into the
evening and exit overnight. Winds become breezy this afternoon with
gusts around 22 kts. Winds reduce into the night with MVFR CIGs
filling over the terminal. These CIGs erode into mid Wednesday
morning with gustier west winds arriving into Wednesday morning.

SFO Bridge Approach...Similar to SFO.

Monterey Bay Terminals...VF lasts into the evening with passing high
clouds. Moderate to breezy westerly winds build this afternoon.
Winds reduce into the evening as IFR CIGS move inland and fill over
MRY, with SNS filling later into the night. CIGS erode in the mid to
late morning on Wednesday as moderate to breezy winds arrive.


(Today through Sunday)
Issued at 1059 AM PDT Tue Jun 25 2024

Moderate to breezy northwesterly continue. Stronger northwesterly
breezes arrive into Wednesday morning creating hazardous
conditions for small crafts across all the waters. Significant
wave heights will continue to abate below 10 feet through the


Issued at 315 AM PDT Tue Jun 25 2024

There is a slight chance of thunderstorms this afternoon, with
limited coverage. Given the elevated nature of any storms that
may develop, any rainfall amounts, if any, will be light with
some VIRGA possible and subsequent gusty winds. Any strikes that
do occur may cause a fire start in the fine fuels.


PZ...Small Craft Advisory from 3 PM to 9 PM PDT Wednesday for Mry Bay.

     Small Craft Advisory from 9 AM Wednesday to 3 AM PDT Thursday
     for Pigeon Pt to Pt Pinos 10-60 NM-Pt Arena to Pt Reyes 0-
     10 nm-Pt Pinos to Pt Piedras Blancas 0-10 nm.

     Small Craft Advisory from 3 PM Wednesday to 3 AM PDT Thursday
     for Pt Arena to Pt Reyes 10-60 NM-Pt Reyes to Pigeon Pt 0-
     10 nm.

     Small Craft Advisory from 9 AM to 9 PM PDT Wednesday for Pigeon
     Pt to Pt Pinos 0-10 nm.



SHORT TERM...Kennedy
LONG TERM....Kennedy

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 Sunday, June 23, 2024

High Temperature

115°F at Palm Springs Asos, CA

Low Temperature

35°F at Leadville, CO

High Precipatation

1.89in at Deland Municipal Airport Sydney H Taylor Field, FL

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