deformed-offering

Weather station scripts - USGS earthquakes

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 https://github.com/ktrue

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 WXForum.net 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, 07-Jul-2020 3:33 PM

PHP Scripts (run on webserver)

Recent nearby earthquakes (from USGS, NRC, BGS) PHP

Here in California, we're a bit sensitive to the earth moving (it happens a lot), so I wrote a PHP scripts to get, cache and reformat the last 7 days of earthquake information so it can be included on the website with links to additional info.

The output of these scripts is XHTML 1.0-Strict compliant. All of them use the same style for inclusion into your webpage as shown in the example below.

Note: Version 2.00 of the script replaced Google maps with Leaflet/OpenStreetMaps scripts, so you no longer need a Google API key (or any API key to use the 5 included maps with the script.
Version 3.00 adds two additional (free) maps: NatGeo and Delorme(Garmin) options. Also tectonic plates and/or faults can be displayed on the map. See the settings below for the geographical areas covered by the fault maps.

If you wish to use the OPTIONAL Mapbox.com tiles (terrain3, Satellite maps), you will need a Mapbox.com API key (called an "Access Token") which can be acquired (for free with 50K accesses usage/month) at:

https://www.mapbox.com/signup/?

in the quakes.php script you can put

$setMapboxAPIkey = '-replace-this-with-your-API-key-here-';

Note: if using the Saratoga template set, put a new entry in Settings.php

$SITE['mapboxAPIkey'] = '-replace-this-with-your-API-key-here-';

A Mapbox API key is OPTIONAL .. you do not need it to use maps from 5 included free map tile providers.

The USA/World earthquake script uses the new USGS GeoJSON feed for data and provides information on USA quakes of 1.0+ magnitude and Worldwide quakes of 4.0+ magnitude. This script is included in the AJAX/PHP Base-USA and Base-World template sets. Sample output with USA settings:

Earthquakes in the past 7 days of magnitude 2.0 or greater within 200 mi
Update time = Fri, 06-Feb-2026 11:06pm PST

Epicenter Near Magnitude Distance to Epicenter Time Link
4 km SE of San Ramon, CA 2.3 00005433 mi 1770417951Fri, 06-Feb-2026 2:45pm PST map
25 km W of Sunnyside-Tahoe City, CA 2.8 000253157 mi 1770405453Fri, 06-Feb-2026 11:17am PST map
7 km WNW of Cobb, CA 2.2 000186116 mi 1770402866Fri, 06-Feb-2026 10:34am PST map
16 km WNW of Bridgeport, CA 2.4 000258160 mi 1770367444Fri, 06-Feb-2026 12:44am PST map
4 km ESE of San Ramon, CA 2.5 00005534 mi 1770337922Thu, 05-Feb-2026 4:32pm PST map
5 km SE of San Ramon, CA 2.7 00005433 mi 1770335993Thu, 05-Feb-2026 3:59pm PST map
30 km ENE of Pinnacles, CA 2.4 00012376 mi 1770335294Thu, 05-Feb-2026 3:48pm PST map
5 km SE of San Ramon, CA 2.4 00005433 mi 1770333125Thu, 05-Feb-2026 3:12pm PST map
5 km SE of San Ramon, CA 2.0 00005333 mi 1770329461Thu, 05-Feb-2026 2:11pm PST map
5 km ESE of San Ramon, CA 2.2 00005434 mi 1770328905Thu, 05-Feb-2026 2:01pm PST map
12 km N of Chico, CA 2.3 000286178 mi 1770326736Thu, 05-Feb-2026 1:25pm PST map
30 km ENE of Pinnacles, CA 2.4 00012376 mi 1770324482Thu, 05-Feb-2026 12:48pm PST map
2 km SSE of San Ramon, CA 2.0 00005434 mi 1770311569Thu, 05-Feb-2026 9:12am PST map
2 km SSE of San Ramon, CA 2.5 00005434 mi 1770310533Thu, 05-Feb-2026 8:55am PST map
6 km W of Cobb, CA 2.0 000186115 mi 1770288104Thu, 05-Feb-2026 2:41am PST map
5 km NNE of Alum Rock, CA 2.3 00002516 mi 1770271147Wed, 04-Feb-2026 9:59pm PST map
8 km W of Cobb, CA 2.3 000186116 mi 1770263142Wed, 04-Feb-2026 7:45pm PST map
6 km NW of The Geysers, CA 2.0 000184115 mi 1770247030Wed, 04-Feb-2026 3:17pm PST map
4 km ESE of San Ramon, CA 2.2 00005534 mi 1770234504Wed, 04-Feb-2026 11:48am PST map
12 km SSW of Johnsville, CA 2.4 000290180 mi 1770230053Wed, 04-Feb-2026 10:34am PST map
14 km S of Tres Pinos, CA 2.0 00009358 mi 1770222913Wed, 04-Feb-2026 8:35am PST map
6 km SE of Sunol, CA 2.0 00003622 mi 1770205746Wed, 04-Feb-2026 3:49am PST map
4 km N of Dublin, CA 2.1 00005232 mi 1770203204Wed, 04-Feb-2026 3:06am PST map
4 km N of Dublin, CA 2.0 00005232 mi 1770191959Tue, 03-Feb-2026 11:59pm PST map
5 km N of Dublin, CA 2.2 00005333 mi 1770174951Tue, 03-Feb-2026 7:15pm PST map
2 km W of Parkfield, CA 2.8 000207129 mi 1770156978Tue, 03-Feb-2026 2:16pm PST map
2 km W of Parkfield, CA 2.0 000207129 mi 1770156660Tue, 03-Feb-2026 2:11pm PST map
4 km ESE of San Ramon, CA 2.5 00005534 mi 1770155126Tue, 03-Feb-2026 1:45pm PST map
3 km E of San Ramon, CA 2.0 00005635 mi 1770151786Tue, 03-Feb-2026 12:49pm PST map
4 km ESE of San Ramon, CA 2.8 00005534 mi 1770138062Tue, 03-Feb-2026 9:01am PST map
4 km SE of San Ramon, CA 2.7 00005434 mi 1770104853Mon, 02-Feb-2026 11:47pm PST map
4 km ESE of San Ramon, CA 2.3 00005434 mi 1770100495Mon, 02-Feb-2026 10:34pm PST map
8 km NE of Alum Rock, CA 2.1 00002818 mi 1770095174Mon, 02-Feb-2026 9:06pm PST map
5 km SE of San Ramon, CA 3.4 00005333 mi 1770093006Mon, 02-Feb-2026 8:30pm PST map
3 km ESE of San Ramon, CA 2.3 00005534 mi 1770082966Mon, 02-Feb-2026 5:42pm PST map
5 km SE of San Ramon, CA 2.6 00005333 mi 1770081875Mon, 02-Feb-2026 5:24pm PST map
4 km ESE of San Ramon, CA 2.2 00005534 mi 1770078368Mon, 02-Feb-2026 4:26pm PST map
4 km ESE of San Ramon, CA 2.0 00005635 mi 1770074930Mon, 02-Feb-2026 3:28pm PST map
4 km ESE of San Ramon, CA 2.2 00005534 mi 1770073762Mon, 02-Feb-2026 3:09pm PST map
5 km SE of San Ramon, CA 2.4 00005333 mi 1770073687Mon, 02-Feb-2026 3:08pm PST map
5 km SE of San Ramon, CA 2.9 00005433 mi 1770073598Mon, 02-Feb-2026 3:06pm PST map
4 km ESE of San Ramon, CA 3.0 00005534 mi 1770073458Mon, 02-Feb-2026 3:04pm PST map
4 km ESE of San Ramon, CA 3.1 00005534 mi 1770072973Mon, 02-Feb-2026 2:56pm PST map
5 km SE of San Ramon, CA 2.2 00005433 mi 1770071929Mon, 02-Feb-2026 2:38pm PST map
4 km ESE of San Ramon, CA 2.5 00005534 mi 1770070019Mon, 02-Feb-2026 2:06pm PST map
4 km N of Dublin, CA 2.1 00005233 mi 1770069629Mon, 02-Feb-2026 2:00pm PST map
4 km ESE of San Ramon, CA 2.2 00005534 mi 1770063464Mon, 02-Feb-2026 12:17pm PST map
5 km SE of San Ramon, CA 2.0 00005434 mi 1770058966Mon, 02-Feb-2026 11:02am PST map
5 km SE of San Ramon, CA 2.4 00005333 mi 1770058268Mon, 02-Feb-2026 10:51am PST map
5 km N of Dublin, CA 2.0 00005333 mi 1770057162Mon, 02-Feb-2026 10:32am PST map
17 km S of Tres Pinos, CA 2.7 00009660 mi 1770054580Mon, 02-Feb-2026 9:49am PST map
4 km ESE of San Ramon, CA 2.5 00005534 mi 1770051822Mon, 02-Feb-2026 9:03am PST map
4 km ESE of San Ramon, CA 2.5 00005534 mi 1770050650Mon, 02-Feb-2026 8:44am PST map
4 km ESE of San Ramon, CA 2.2 00005534 mi 1770050297Mon, 02-Feb-2026 8:38am PST map
4 km SE of San Ramon, CA 2.2 00005434 mi 1770049182Mon, 02-Feb-2026 8:19am PST map
4 km ESE of San Ramon, CA 2.8 00005534 mi 1770047648Mon, 02-Feb-2026 7:54am PST map
5 km SE of San Ramon, CA 2.6 00005333 mi 1770047306Mon, 02-Feb-2026 7:48am PST map
4 km ESE of San Ramon, CA 2.8 00005534 mi 1770046921Mon, 02-Feb-2026 7:42am PST map
4 km ESE of San Ramon, CA 2.5 00005434 mi 1770046873Mon, 02-Feb-2026 7:41am PST map
4 km SE of San Ramon, CA 2.2 00005434 mi 1770046812Mon, 02-Feb-2026 7:40am PST map
4 km ESE of San Ramon, CA 2.8 00005534 mi 1770046566Mon, 02-Feb-2026 7:36am PST map
5 km SE of San Ramon, CA 2.0 00005333 mi 1770046546Mon, 02-Feb-2026 7:35am PST map
4 km SE of San Ramon, CA 2.5 00005434 mi 1770046496Mon, 02-Feb-2026 7:34am PST map
4 km SE of San Ramon, CA 2.6 00005434 mi 1770046367Mon, 02-Feb-2026 7:32am PST map
5 km SE of San Ramon, CA 2.0 00005333 mi 1770046321Mon, 02-Feb-2026 7:32am PST map
5 km SSE of San Ramon, CA 3.8 00005333 mi 1770046065Mon, 02-Feb-2026 7:27am PST map
4 km SE of San Ramon, CA 2.1 00005333 mi 1770045984Mon, 02-Feb-2026 7:26am PST map
5 km SE of San Ramon, CA 2.9 00005433 mi 1770045797Mon, 02-Feb-2026 7:23am PST map
4 km SE of San Ramon, CA 2.9 00005433 mi 1770045784Mon, 02-Feb-2026 7:23am PST map
5 km SE of San Ramon, CA 2.5 00005333 mi 1770045777Mon, 02-Feb-2026 7:22am PST map
4 km ESE of San Ramon, CA 2.0 00005534 mi 1770045297Mon, 02-Feb-2026 7:14am PST map
4 km SE of San Ramon, CA 2.3 00005433 mi 1770044996Mon, 02-Feb-2026 7:09am PST map
4 km SE of San Ramon, CA 2.8 00005434 mi 1770044826Mon, 02-Feb-2026 7:07am PST map
4 km ESE of San Ramon, CA 2.8 00005534 mi 1770044774Mon, 02-Feb-2026 7:06am PST map
5 km N of Dublin, CA 2.3 00005333 mi 1770044676Mon, 02-Feb-2026 7:04am PST map
3 km ESE of San Ramon, CA 2.7 00005534 mi 1770044636Mon, 02-Feb-2026 7:03am PST map
4 km SE of San Ramon, CA 4.2 00005434 mi 1770044473Mon, 02-Feb-2026 7:01am PST map
4 km SE of San Ramon, CA 2.2 00005434 mi 1770044442Mon, 02-Feb-2026 7:00am PST map
4 km ESE of San Ramon, CA 2.5 00005534 mi 1770044177Mon, 02-Feb-2026 6:56am PST map
4 km ESE of San Ramon, CA 2.5 00005534 mi 1770043737Mon, 02-Feb-2026 6:48am PST map
4 km ESE of San Ramon, CA 2.0 00005534 mi 1770043145Mon, 02-Feb-2026 6:39am PST map
4 km SE of San Ramon, CA 2.0 00005434 mi 1770042754Mon, 02-Feb-2026 6:32am PST map
4 km SE of San Ramon, CA 3.1 00005333 mi 1770042596Mon, 02-Feb-2026 6:29am PST map
4 km SSE of San Ramon, CA 3.8 00005333 mi 1770042420Mon, 02-Feb-2026 6:27am PST map
3 km SSE of Redwood Valley, CA 2.3 000242150 mi 1770042224Mon, 02-Feb-2026 6:23am PST map
17 km S of Tres Pinos, CA 2.6 00009559 mi 1770034422Mon, 02-Feb-2026 4:13am PST map
12 km E of Mammoth Lakes, CA 2.4 000284176 mi 1770027286Mon, 02-Feb-2026 2:14am PST map
6 km SSW of Gilroy, CA 2.8 00005232 mi 1769956028Sun, 01-Feb-2026 6:27am PST map
9 km SSE of Lake Pillsbury, CA 2.0 000241150 mi 1769942633Sun, 01-Feb-2026 2:43am PST map

89 earthquakes found. Click on location or map links for more details from the USGS

Script by Saratoga-weather.org

This was invoked by using the following code:

<?php 
# settings -------------------------- 
  $doIncludeQuake = true;
# uncomment ONE of the $setDistanceDisplay lines to use as template for distance displays  
#  $setDistanceDisplay = 'mi (km)';
  $setDistanceDisplay = 'mi';
#  $setDistanceDisplay = 'km (mi)';
#  $setDistanceDisplay = 'km';

  $setDistanceRadius  = 1000;  // same units as first unit in $setDistanceDisplay
# NOTE: quakes of magnitude 1.0+ are available for USA locations only.
#    non-USA location earthquakes of magnitude 4.0+ are the only ones available from the USGS
  $setMinMagnitude = '2.0';  // minimum Richter Magnitude to display
  $setHighMagnitude = '4.0';  // highlight this Magnitude and greater
  
# script will use your $SITE[] values for latitude, longitude, cityname, timezone and time display format
# but you can override them if you with with the commented statements below:
  $setLatitude  = 37.2746251;    //North=positive, South=negative decimal degrees
  $setLongitude = -122.0229656;   //East=positive, West=negative decimal degrees
# The above settings are for saratoga-weather.org location
#  $setLocationName = 'Saratoga, CA'; // city/town name for lat/long above 
#
  $setTimeZone = "America/Los_Angeles";  //NOTE: this *MUST* be set correctly to
# translate UTC times to your LOCAL time for the displays.
# Use http://www.php.net/manual/en/timezones.php to find the timezone suitable for
#  your location.

#  pick a format for the time to display ..uncomment one (or make your own)
 $setTimeFormat = 'D, Y-m-d H:i:s T';  // Fri, 2006-03-31 14:03:22 TZone
#  $setTimeFormat = 'D, d-M-Y H:i:s T';  // Fri, 31-Mar-2006 14:03:22 TZone

  $setDoLinkTarget = false;   // =true; to have links open in new page, =false; for XHTML 1.0-Strict

	$setMapProvider = 'Esri_WorldTopoMap'; // ESRI topo map - no key needed
# $setMapProvider = 'OSM';     // OpenStreetMap - no key needed
# $setMapProvider = 'Terrain'; // Terrain map by stamen.com - no key needed
# $setMapProvider = 'OpenTopo'; // OpenTopoMap.com - no key needed
# $setMapProvider = 'Wikimedia'; // Wikimedia map - no key needed
# $setMapProvider = 'NatGeo';  // National Geographic world map -no key needed  
# $setMapProvider = 'Delorme';  // Garmin world map -no key needed  
# $mapProvider = 'MapboxSat';  // Map by Mapbox.com - API KEY needed in $setMapboxAPIkey 
# $mapProvider = 'MapboxTer';  // Map by Mapbox.com - API KEY needed in $setMapboxAPIkey 
 $setMapboxAPIkey = '--mapbox-API-key--';  // use this for the API key to MapBox
 
# for fault displays
 $setFaultDisplay = 'USGS'; // ='' for none, see below for more choices
# Note: not all fault displays have entries for all countries. You'll need to choose the one that
#   displays the information for your geography.
#
# 'PH' covers the Phillipines only
# 'USGS' covers the lower-48 CONUS states only but with fault types/names/ages
# 'USGS2' covers all 50 US states, but with only small/medium/large fault types (no descriptions)
# 'USGS3' covers the mostly western CONUS lower-48 states only  with fault names and types only
# 'GEM' covers much of the world (omitting Canada, Scandanavia and UK/Ireland)
# 'WORLD' covers most of the world with 4 fault types (  rift, step, tectonic contact, thrust-fault)
# 'BGS' convers the UK (England, Wales, Scotland, Northern Ireland) 
#

 $setPlateDisplay = true;  // =true; show tectonic plates ; =false; suppress tectonic plate display
 
  include_once("quake-json.php");

?>

Also required is the styling and JavaScript <script> statements in the <head>...</head> part of the page (see the sample quakes.php page in the distribution quake-json.zip package for details).

The USGS GeoJSON earthquake script (V3.04 - 07-Jul-2020):
download .zip package [ see version history ]

This script loads the GeoJSON feed for all earthquakes in the last 7 days from the USGS. For the USA, magnitude 1.0+ quakes are available. For non-USA locations, the USGS only provides information on magnitude 4.0+ based on the data they receive from partner seismographic organizations. If you are installing the script for standalone use, do download the .ZIP package as it contains the graphics files needed for the Google Map. If you are using the AJAX/PHP template set (V3+), the script is already integrated into the Base-Canada, Base-USA, and Base-World templates.

For Base-World template users, the script is compatible with the language translation features of the template set. You may need to add to your language-LL.txt translation file the following entries (translated) in order to show the ouput in language LL.
Note: the |of| entry below is used in the reports for quake location as in:
  20 mi NNW of Saratoga, California

langlookup|Update time|Update time|
langlookup|of|of|
langlookup|No earthquakes of magnitude|No earthquakes of magnitude|
langlookup|or greater within|or greater within|
langlookup|reported in last 7 days|reported in last 7 days|
langlookup|Cluster - click to expand details|Cluster - click to expand details|
langlookup|Enable JavaScript to view the Google Map.|Enable JavaScript to view the Google Map.|
langlookup|Earthquakes in the past 7 days of magnitude|Earthquakes in the past 7 days of magnitude|
langlookup|or greater within|or greater within|
langlookup|Epicenter Near|Epicenter Near|
langlookup|Magnitude|Magnitude|
langlookup|Distance to Epicenter|Distance to Epicenter|
langlookup|Time|Time|
langlookup|Link|Link|
langlookup|map|map|
langlookup|Note: Click on column heading marked with|Note: Click on column heading marked with|
langlookup|to sort column contents.|to sort column contents.|
langlookup|earthquakes found. Click on location or map links for more details from the <a href="http://earthquake.usgs.gov/earthquakes/map/">USGS</a>|earthquakes found. Click on location or map links for more details from the <a href="http://earthquake.usgs.gov/earthquakes/map/">USGS</a>|
langlookup|Depth|Depth|
langlookup|Distance to epicenter|Distance to epicenter|
langlookup|Map and data courtesy of|Map and data courtesy of|
langlookup|United States Geological Survey|United States Geological Survey|

The Canada earthquake script : demo and download [ see version history ]
Documentation on how to customize the script is in comments contained in the source. For anywhere in Canada, you just have to change $myLat and $myLong to your station's decimal latitude and longitude to see it work in your area. Defaults are for magnitude 2.0 (or greater) within a 500 km radius. This script uses data from Natural Resources Canada website and returns earthquake activity over the last 30 days. Version 1.03+ now provides both English and French display.

The UK earthquake script : demo and download [ see version history ]
Documentation on how to customize the script is in comments contained in the source. For anywhere in the United Kingdom, you just have to change $myLat and $myLong to your station's decimal latitude and longitude to see it work in your area. Defaults are for earthquakes within a 500 km radius. This script uses data from British Geological Survey website and returns earthquake activity over the last 30 days.
BGS data is used with permission as long as the attribution built into the script displays with the script output.

Deprecated Scripts

With the release of quake-json.php script on 8-Sep-2012, the following scripts are no longer maintained as the USGS is deprecating the pages on their website that these scripts require:

  • quake-CANV.php
  • quake-USA.php
  • quake-WORLD.php and quake-WORLD-ML.php

The quake-json.php script uses the USGS new GeoJSON feed for 1+ (USA) and 4+ (World) magnitude events and replaces the functionality of the above scripts.

deformed-offering