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 190531

Area Forecast Discussion
National Weather Service San Francisco Bay Area
1031 PM PDT Wed Sep 18 2019

.SYNOPSIS...A warming and drying trend is forecast for late week
and weekend as high pressure builds in from the eastern Pacific.
A low pressure system moving to our east early next week may create
the potential for dry offshore winds and increased fire concerns.

&& of 9:52 PM PDT Wednesday...Rain gages over Sonoma
county and San Mateo county as well as over Alameda county generally
had the highest rain totals from this morning`s frontal passage. The
highest reports made available to our office include Oak Ridge in
Sonoma county with 0.19" and Half Moon Bay varying between 0.12" and
0.10" and Alameda 0.17" rain. Similar to Monday`s trough passage
Kentfield once again did not receive measurable rain today at the
official cooperative station. The farther south the front moved the
weaker it became and many places did not receive measurable rain.

From the coastal North Bay along the San Francisco peninsula coast
including the Bay Area mountains highs today were mostly in the
mid 60s to 70. Along San Francisco Bay to the inland valleys highs
were mostly in the 70s and over interior Monterey and San Benito
counties highs were as warm as the upper 70s to middle 80s.

Daytime convective clouds generated from surface warming and residual
muggy air were capped by a subsidence inversion in the lower levels
of the atmosphere; the inversion was based near 6,400 feet on the
00z Oakland upper air sounding. Patchy low clouds are redeveloping
from the South Bay to the Central Coast, otherwise a drying trend
is underway for the overnight hours. Thursday is shaping up to be
sunny to mostly sunny with highs in the 60s at the coast to the 70s
to lower 80s inland.

500 mb height troughing over the West Coast will slowly advance to
the east over the Intermountain West through late week. A closed
500 mb 591 decameter high pressure center over the eastern Pacific
will weaken and retrograde through Saturday. A return to 500 mb
ridging will return to NorCal Thursday, but a temporary retrogression
of the eastern Pacific high will offset rising heights over the
cwa to some extent into the weekend. Another upstream trough over
the Pacific will pass over the Gulf of Alaska and the Pacific
Northwest over the weekend, upon reaching the Intermountain West
it will tend to move southeastward and slow as the mid-latitude
flow over the western CONUS buckles under amplification. This may
bring a period of offshore wind flow to our cwa early next week as
surface pressures build over the Great Basin with implications mostly
on rising fire weather concerns as well as rising temperatures thus
it bears watching in subsequent model runs. Current ECMX MOS
guidance trends temperatures warmer to hotter peaking on Tuesday of
next week with highs in the 90s inland. The ECMWF and GFS are
showing good model agreement in the large scale 500 mb height
pattern tonight into early next week, the pattern then becoming
noisy with diverging solutions by the middle of next week.

For additional details please see previous forecast discussion.


.PREV of 02:13 PM PDT Wednesday...As skies clear
tonight, cool overnight lows are expected in the valleys with
upper 40s to lower 50s with mid to upper 50s near the coast and
bays. The base of the upper trough responsible for bringing us
scattered showers and cooler temperatures will shift through our
forecast area on Thursday. Highs are expected to be similar to
today, ranging from the upper 60s at the coast to the 70s and
lower 80s inland, which are near to slightly below normal for the

High pressure over the eastern Pacific will then begin to build
towards the West Coast on Friday and Saturday, resulting in a
warming trend for the region. The strongest warming will be felt
inland, with highs on Friday reaching the mid to upper 80s and
upper 80s to mid 90s on Saturday. Light offshore flow and a lack
of a strong marine layer will also allow temperatures to warm at
the coast, where temperatures in the 70s to low 80s are

Temperatures trend slightly lower Sunday into Monday as another
upper level trough drops southward into the Pacific Northwest and
into the Intermountain West. There remains some uncertainty with
the track, but at this time, dry conditions look most likely with
temperatures near to slightly above seasonal averages. Depending
on the exact track of the aforementioned system, the development
of offshore flow looks possible early next week which may result
in an increase in temperatures and much drier conditions. This
pattern will be closely monitored in the coming days as it may
create the potential for increased fire concerns.


.AVIATION...As of 10:32 PM PDT Wednesday...Clouds have remained
around the MRY Bay Area and over the coastal hills this evening
while the SFO Bay Area has mostly cleared out. Models indicate
decreasing low-level moisture so latest forecast leaves out cigs
for the SFO Bay Area. MVFR remains in the forecast for MRY/SNS due
to the clouds that are there now.

Vicinity of KSFO...VFR expected with some SCT-BKN overnight.

SFO Bridge Approach...Similar to KSFO.

Monterey Bay Terminals...Cloud layers around 1500 ft and 4000 ft.
MVFR cigs are expected after 09-10Z.

&& of 10:21 PM PDT Wednesday...Low pressure moving into
the Pacific Northwest will keep light northwest winds through
tonight. Winds will increase Thursday through Friday as high
pressure builds behind the departing low.


     .Tngt...SCA...Pt Pinos to Pt Piedras Blancas 0-10 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.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, September 17, 2019

High Temperature

104°F at Andalusia/Opp Arpt, AL

Low Temperature

27°F at Mammoth/June Lakes, CA

High Precipatation

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