(.*)
Banner Logo About UsRadarPicturesForecastWX RadioLive Stream 
    

Forecast for Wichita Falls

CRH.noaa.gov redirects (no point forecasts) // Version 2.02 - 02-Mar-2007 - added auto-failover to CRH and better include in page. // Version 2.03 - 29-Apr-2007 - modified for /images/wtf -> /forecast/images change // Version 2.04 - 05-Jun-2007 - improvement to auto-failover // Version 2.05 - 29-Jun-2007 - additional check for alternative no-icon forecast, then failover. // //import NOAA Forecast info //data ends up in three different arrays: //$forecasticons[x] x = 0 thru 9 This is the icon and text around it //$forecasttemp[x] x= 0 thru 9 This is forecast temperature with styling //$forecasttitles[x] x = 0 thru 12 This is the title word for the time period //$forecasttext[x] x = 0 thru 12 This is the detail text for the forecast // //$forecastupdate This is the time of last update //$forecastcity This is the city name for the forecast //$forecastoffice This is the NWS Office providing the forecast // //Also, in order for this to work correctly, you need the NOAA icons (or make your own... //there are over 200!). These need to be placed in the path where the original NOAA icons //are located. In my case, they are at: \forecast\images\ //properly (so make a folder in your web HTML root called "forecast", then make a folder in it //called "images", and place the icons in this folder) // //http://members.cox.net/carterlakeweather/forecasticons.zip (380K) // //URL below --MUST BE-- the Printable Point Forecast from the NOAA website // //Not every area of the US has a printable point forecast // //This script will ONLY WORK with a printable point forecast! // //To find yours in your area: // //Go to www.noaa.gov //Click on the Storm Watch map (middle lower left of page) //Click on your state //Click on your area of the state //Scroll down to the "Additional Forecasts & Info" //Click on Printable Forecast //------------------------------------------------*/ // // also set your NOAA warning zone here to use for automatic backup in case // the point printable forecast is not available. $NOAAZone = 'ALZ064'; // change this line to your NOAA warning zone. // Get the forecast.txt file or a new one from NOAA // You have to have a forecast.txt in place for this script to work // You can see ours at http://www.carterlake.org/forecast.txt // This is version 1.2 with Ken's modifications from Saratoga Weather // http://saratoga-weather.org/ // You can now force the cache to update by adding ?force=1 to the end of the URL if ( empty($_REQUEST['force']) ) $_REQUEST['force']="0"; $Force = $_REQUEST['force']; $forceBackup = false; if ($Force > 1) {$forceBackup = true; } $cacheName = "forecast.txt"; $fileName = "http://forecast.weather.gov/MapClick.php?CityName=Wichita+Falls&state=TX&site=OUN&textField1=33.8979&textField2=-98.5163&TextType=2"; // dont change the next line.... $backupfileName = "http://www.crh.noaa.gov/zones/$NOAAZone.php?zo=1"; $Status = "\n"; if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) { //--self downloader -- $filenameReal = $_SERVER["PATH_TRANSLATED"]; $filenameLcl = substr($PHP_SELF,1); $download_size = filesize($filenameReal); header('Pragma: public'); header('Cache-Control: private'); header('Cache-Control: no-cache, must-revalidate'); header("Content-type: text/plain"); header("Accept-Ranges: bytes"); header("Content-Length: $download_size"); header('Connection: close'); readfile($filenameReal); exit; } $usingFile = ""; if ($Force==1) { $html = fetchUrlWithoutHanging($fileName,$cacheName); if (preg_match('/Temporary|Location:|defaulting to/Uis',$html)) { $usingFile = "(Zone forecast)"; $html = fetchUrlWithoutHanging($backupfileName,$cacheName); } $fp = fopen($cacheName, "w"); $write = fputs($fp, $html); fclose($fp); } if ($Force==2) { $html = fetchUrlWithoutHanging($backupfileName,$cacheName); $fp = fopen($cacheName, "w"); $write = fputs($fp, $html); fclose($fp); $usingFile = "(Zone forecast)"; } // The number 1800 below is the number of seconds the cache will be used instead of pulling a new file // 1800 = 60s x 30m so it retreives every 30 minutes. if (filemtime($cacheName) + 1800 > time()) { $html = implode('', file($cacheName)); if (preg_match('/Temporary|Location:|defaulting to/is',$html)) { $usingFile = "(Zone forecast)"; $html = fetchUrlWithoutHanging($backupfileName,$cacheName); } } else { $html = fetchUrlWithoutHanging($fileName,$cacheName); if (preg_match('/Temporary|Location:|defaulting to/Uis',$html)) { $usingFile = "(Zone forecast)"; $html = fetchUrlWithoutHanging($backupfileName,$cacheName); } $fp = fopen($cacheName, "w"); $write = fputs($fp, $html); fclose($fp); } // Just get the top of the NWS page for editing $ERHtoCRH = preg_match('|/HW3php/images/fcicons/|i',$html); // here with ERH->CRH redirect? if ($ERHtoCRH) { // using the ERH->CRH redirect to zone forecast preg_match( '|

\s+(.*)
|Uis', $html, $betweenspan); // print "\n"; $forecastop = $betweenspan[1]; preg_match_all("/(.*)<\/td>/Uis", $forecastop, $headers); $forecaststuff = $headers[1]; // $Status .= "\n"; // 0..8 = Day // 9..17 = icon img statement // 18..26 = forecast (short form) // 27..35 = temps Hi/Lo // 36..44 = PoP (or empty). for ($i=0;$i<=8;$i++) { $forecaststuff[$i+9] = preg_replace( '|/HW3php/images/fcicons/|','/forecast/images/',$forecaststuff[$i+9]); if (! preg_match('|
|i',$forecaststuff[$i]) ) { $forecaststuff[$i] .= '
'; } $forecaststuff[$i+18] = preg_replace('|
|is','
',$forecaststuff[$i+18]); $forecaststuff[$i+27] = trim($forecaststuff[$i+27]); $forecaststuff[$i+27] = '' . preg_replace( '|(.*)|Uis', "$2",$forecaststuff[$i+27]) . ''; $forecaststuff[$i+27] = preg_replace('|
|is','
',$forecaststuff[$i+27]); $forecaststuff[$i+36] = trim($forecaststuff[$i+36]); preg_match( // just get numeric value for pop if any. '|(\d+)|is',$forecaststuff[$i+36],$temp); if (! empty($temp[1]) ) { $PoP[$i] = $temp[1]; } else { $PoP[$i] = ''; } // $Status .= "\n"; if ($PoP[$i] > 0) { // change name to include PoP $forecaststuff[$i+9] = preg_replace('|\.jpg|s',$PoP[$i] . '.jpg',$forecaststuff[$i+9]); } // fix up tag for XHTML 1.0-Strict $tag = $forecaststuff[$i+18]; // raw terse forecast. if ($PoP[$i] > 0) { $tag .= ". Chance of measurable precipation is " . $PoP[$i] . '%.'; } $tag = preg_replace('|
|is',' ',$tag); $Status .= "\n"; $forecaststuff[$i+9] = preg_replace('|">$|i', "\" alt=\"$tag\" title=\"$tag\" />",$forecaststuff[$i+9]); $forecasticons[$i] = $forecaststuff[$i] . '
' . $forecaststuff[$i+9] . '
' . $forecaststuff[$i+18]; $forecasttemp[$i] = $forecaststuff[$i+27]; $forecastpop[$i] = $forecaststuff[$i+36]; } } else { // original srh/crh/erh format point printable forecast preg_match('|
(.*)<\/td>/Uis", $forecastop, $headers); $forecasticons = $headers[1]; } // saratoga-weather.org mod: fix up html for XHTML 1.0-Strict // $Status .= "\n"; for ($i=0;$i<=8;$i++) { $forecasticons[$i] = preg_replace('|/images/wtf|Uis', '/forecast/images',$forecasticons[$i]); $forecasticons[$i] = preg_replace('|/forecast/images|Uis', './forecast/images',$forecasticons[$i]); $forecasticons[$i] = preg_replace('|

\s+$|is', "",$forecasticons[$i]); // $forecasticons[$i] = preg_replace('|temperatures|is','temps',$forecasticons[$i]); // $forecasticons[$i] = preg_replace('|Falling|is',' Falling',$forecasticons[$i]); $forecasticons[$i] = preg_replace('|\'|is','"',$forecasticons[$i]); // change all ' to " $forecasticons[$i] = preg_replace('|\\\\" >
|is','" />
',$forecasticons[$i]); $forecasticons[$i] = preg_replace('|(.*)|Uis', "$2",$forecasticons[$i]); preg_match_all('|
([^<]+)(.*)|is',$forecasticons[$i],$matches); // $Status .= "\n"; if(preg_match('||i',$matches[2][0])) { $t = $matches[2][0]; $t = preg_replace('|([^|i', "\"\\3\"",$t); $matches[2][0] = $t; } if (! $ERHtoCRH) { $forecasttemp[$i] = $matches[1][0] . $matches[2][0]; // just the temp line } // remove the temp from the forecasticons $forecasticons[$i] = preg_replace('|'.$matches[0][0].'|is','',$forecasticons[$i]); // fix up the
to be
for XHTML compatibility $forecasticons[$i] = preg_replace('|
|Uis','
',$forecasticons[$i]); // $forecasttemp[$i] = preg_replace('|
|Uis','
',$forecasttemp[$i]); // $forecasttemp[$i] = trim($forecasttemp[$i]); } // $Status .= "\n"; // end saratoga-weather.org XHTML 1.0-Strict mod if ($ERHtoCRH) { // special handling for ERH->CRH redirection // Now get just the bottom of the NWS page for editing preg_match('|alt="Detailed Forecast">
(.*) |s', $html, $betweenspan); $forecast = $betweenspan[1]; // Chop up each title text and place in array preg_match_all('|(.*)|Ui', $forecast, $headers); $forecasttitles = $headers[1]; // Chop up each forecast text and place in array preg_match_all('|\.\.\.(.*)
|Uis', $forecast, $headers); $forecasttext = $headers[1]; // Grab the Last Update date and time. preg_match('|Forecast as of: (.*)\ |', $html, $betweenspan); $forecastupdated = $betweenspan[1]; $forecastupdated = preg_replace('|<[^>]+>|Uis','',$forecastupdated); // remove html markup // saratoga-weather.org mod: // Grab the NWS Forecast for (city name) preg_match('|class="white1">\s*(.*)(.*)|Uis',$html,$betweenspan); $forecastoffice = trim($betweenspan[1]); $forecastoffice = preg_replace('|
|s','',$forecastoffice); } else { // begin regular handling // Now get just the bottom of the NWS page for editing preg_match('|
(.*)
|s', $html, $betweenspan); $forecast = $betweenspan[1]; // Chop up each title text and place in array preg_match_all('|(.*): |Ui', $forecast, $headers); $forecasttitles = $headers[1]; // Chop up each forecast text and place in array preg_match_all('|(.*)
|Ui', $forecast, $headers); $forecasttext = $headers[1]; // Grab the Last Update date and time. preg_match('|Last Update: (.*)|', $html, $betweenspan); $forecastupdated = $betweenspan[1]; $forecastupdated = preg_replace('|<[^>]+>|Uis','',$forecastupdated); // remove html markup // saratoga-weather.org mod: // Grab the NWS Forecast for (city name) preg_match('|NWS Forecast for: (.*)|',$html,$betweenspan); $forecastcity = $betweenspan[1]; // Grab the Issued by office preg_match('|Issued by: (.*)
|',$html,$betweenspan); $forecastoffice = $betweenspan[1]; } // end regular handling $IncludeMode = false; $PrintMode = true; if (isset($doPrintNWS) && ! $doPrintNWS ) { return; } if (isset($_REQUEST['inc']) && strtolower($_REQUEST['inc']) == 'noprint' ) { return; } if (isset($_REQUEST['inc']) && strtolower($_REQUEST['inc']) == 'y') { $IncludeMode = true; } if (isset($doIncludeNWS)) { $IncludeMode = $doIncludeNWS; } // end saratoga-weather.org mod function fetchUrlWithoutHanging($url,$cacheurl) { // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed $numberOfSeconds=4; // Suppress error reporting so Web site visitors are unaware if the feed fails error_reporting(0); // Extract resource path and domain from URL ready for fsockopen $url = str_replace("http://","",$url); $urlComponents = explode("/",$url); $domain = $urlComponents[0]; $resourcePath = str_replace($domain,"",$url); // Establish a connection $socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds); if (!$socketConnection) { $html = implode('', file($cacheurl)); return($html); // You may wish to remove the following debugging line on a live Web site // print(""); } // end if else { $xml = ''; fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n"); // Loop until end of file while (!feof($socketConnection)) { $xml .= fgets($socketConnection, 4096); } // end while fclose ($socketConnection); } // end else return($xml); } // end function if (! $IncludeMode and $PrintMode) { ?> NWS Forecast for <?php echo $forecastcity; ?>
Forecast blank?
Force Update

'; } if ($PrintMode) {?>
National Weather Service Forecast for: Issued by:
Updated:
  $forecasticons[$i]\n"; } ?> $forecasttemp[$i]\n"; } ?>
\n"; print "\n"; print "\n"; print "\n"; } ?>
$forecasttitles[$i]
 
$forecasttext[$i]

Forecast from NOAA-NWS for .

 

Questions or Comments? Contact Us




Featured On:
Go to fullsize image
   Copyright 2009 (C) TriCountyWeather.com                                                                                                                                                                               Scott McLaughlin