At Mark's request, I've redone the usaextremes.php script from relayweather to use WeatherUnderground as the source for the data.
Here's the code for usaextremes.php <?php
############################################################################
#
# Project: USA Extremes
# Module: usaextremes.php
# Purpose: Provides USA Extremes for Web page display
# Authors: Michael (michael@relayweather.com)
# Ken True (webmaster@saratoga-weather.org) V2.01
############################################################################
# Usage: Place the following on your webpage
# CHMOD 666 for cacheFile2.php
# include_once('usaextremes.php');
#
# Then call the following tags within the page where you would like them displayed:
# $usahigh
# $usalow
# $usaprecip
#
# Note: allow_url_fopen = on
# in your php.ini is required to run this script.
############################################################################
// version
// Version 2.00 - 14-Sep-2010 - initial release
// Version 2.01 - 21-Sep-2012 - adapted for WeatherUnderground use - K. True
$usaextremesverion = "2.01";
echo "<!-- USA Extremes Script Version $usaextremesverion. -->\n";
/////////////////////////////////////////////////////////////////////////////
//SETTINGS START HERE////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Site to Parse
$url2 = "http://www.wunderground.com/climate/extremes.asp";
// Set the time zone
$ourTZ = 'America/Los_Angeles';
// Name of cache file -- This file must be set to CHMOD-666
$cacheFile2 = "usaextremesCache.php";
// Age of cache file before re-fetch caching time, in seconds (3600 = 1 hour)
$cache_life = '3600';
/////////////////////////////////////////////////////////////////////////////
//END SETTINGS///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
if (file_exists($cacheFile2)) {
$filemtime = filemtime($cacheFile2);
$filesize = filesize($cacheFile2);
if (0 == $filesize){
$filemtime = 0;
}
} else {
$filemtime = 0;
}
// open the cache file and write the new data and then close the file.
$forceRefresh = (isset($_REQUEST['force']))?true:false;
$current_time = time();
$cache_age = $current_time - $filemtime;
if ($forceRefresh or $cache_age >= $cache_life){
$html2 = implode(' ', file($url2));
$fp2 = fopen($cacheFile2, 'w');
fwrite($fp2, $html2);
fclose($fp2);
echo "<!-- The cache life HAS expired and fresh data re-wrote the cache file -->\n";
} else {
echo "<!-- The cache life HAS NOT expired and fresh data was not written to the cache file -->\n";
// Open the cache file, read it, then close it
$handle2 = fopen($cacheFile2, "r");
$filesize = filesize($cacheFile2);
$html2 = fread($handle2, $filesize);
fclose($handle2);
}
//Finds USA High
preg_match_all('|<div id="highTemp"[^>]*>(.*)</div>|Uis', $html2, $matches);
// print "<pre>\n".print_r($matches,true)."</pre>\n";
if(isset($matches[1][0])) {
$hightable = $matches[1][0];
preg_match_all('|<td>(.*)</td>|Uis',$hightable,$matches);
// print "<pre>\n".print_r($matches,true)."</pre>\n";
$usahigh = trim(preg_replace("|\n|is",'',strip_tags($matches[1][2]).'<br/>'.strip_tags($matches[1][0])));
print "<!-- usahigh='$usahigh' -->\n";
} else {
$usahigh = 'N/A';
}
//Finds USA Low
preg_match_all('|<div id="lowTemp"[^>]*>(.*)</div>|Uis', $html2, $matches);
// print "<pre>\n".print_r($matches,true)."</pre>\n";
if(isset($matches[1][0])) {
$lowtable = $matches[1][0];
preg_match_all('|<td>(.*)</td>|Uis',$lowtable,$matches);
// print "<pre>\n".print_r($matches,true)."</pre>\n";
$usalow = trim(preg_replace("|\n|is",'',strip_tags($matches[1][2]).'<br/>'.strip_tags($matches[1][0])));
print "<!-- usalow='$usalow'-->\n";
} else {
$usalow = 'N/A';
}
//Finds USA High Precip
preg_match_all('|<div id="precip"[^>]*>(.*)</div>|Uis', $html2, $matches);
// print "<pre>\n".print_r($matches,true)."</pre>\n";
if(isset($matches[1][0])) {
$raintable = $matches[1][0];
preg_match_all('|<td>(.*)</td>|Uis',$raintable,$matches);
// print "<pre>\n".print_r($matches,true)."</pre>\n";
$usaprecip = trim(preg_replace("|\n|is",'',strip_tags($matches[1][2]).'<br/>'.strip_tags($matches[1][0])));
print "<!-- usaprecip='$usaprecip' -->\n";
} else {
$usaprecip = 'N/A';
}
print '<!-- $filemtime = '.$filemtime.' $cache_age = '.$cache_age.' seconds.' . " -->\n";
print "<!-- Cache refresh rate = $cache_life seconds. Cache age = $cache_age seconds. -->\n";
?>
After installing, you may need to run it with ?force=1 to clear the cache and reload the page from Wunderground.
Let me know how it works for you...
Best regards,
Ken