This code's pretty old actually...
This code keeps a timing out URL from timing out the webpage...
function forecastfetchUrlWithoutHanging($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("<!-- Network error: $errstr ($errno) -->");
} // 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, 128);
} // end while
fclose ($socketConnection);
} // end else
return($xml);
} // end function
Then this code actually makes the HTML based on the advisory...
//import NOAA Advisory info
//data can be altered by changing the zone and county numbers
//Target data ends up in $warnscroll
$html="";
$html = fetchUrlWithoutHanging('http://www.crh.noaa.gov/showsigwx.php?warnzone=IAZ069&warncounty=IAC155');
//Get the advisory headers and put them in an array
preg_match_all('|<h3>(.*)</h3>|', $html, $headers);
$warnheaders = $headers[1];
//If there is more than one advisory, we need to set its priority
//If there aren't any advsiories... we stop here... displaying nothing
if (count($warnheaders) >= 1) {
$i = 0;
$flag = 0;
$warnscroll = "";
//First, around here tornados are the biggest danger. A warning is critical information.
//Display this one first no matter what!
while ($i < count($warnheaders)):
if (preg_match("/Tornado Warning/i", $warnheaders[$i])) {
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="tornadowarningBox"><a href="wx4.php" style="color: #FFFFFF;"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
//Next if there are none of the above found. Display the first warning message.
if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Warning/i", $warnheaders[$i])) {
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="warningBox"><a href="wx4.php" style="color: #FFFFFF";><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}
//Next if there are none of the above found. Display the first watch message.
if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Watch/i", $warnheaders[$i])) {
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="watchBox"><a href="wx4.php"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}
//Next if there are none of the above found. Display the first advisory message.
if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Advisory/i", $warnheaders[$i])) {
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="advisoryBox"><a href="wx4.php"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}
//Next if there are none of the above found. Display the first statement message.
if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Statement/i", $warnheaders[$i])) {
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="advisoryBox"><a href="wx4.php"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}
}
Displaying the advisory itself is simple...
<?echo $warnscroll?>
How the advisory shows up is controlled with .css code... in my main .css file... this makes it really really easy to change the appearance... no editing the PHP... just change the .css and reupload.
.warningBox {
color: white;
font-size: 12px;
text-align: center;
background-color: #FF9900;
margin: 0 0 0 0;
padding: .5em 0em .5em 0em;
border: 1px dashed rgb(34,70,79);
}
.watchBox {
color: black;
font-size: 12px;
text-align: center;
background-color: #FFCC00;
margin: 0 0 0 0;
padding: .5em 0em .5em 0em;
border: 1px dashed rgb(34,70,79);
}
.advisoryBox {
color: black;
font-size: 12px;
text-align: center;
background-color: #F0E68C;
margin: 0 0 0 0;
padding: .5em 0em .5em 0em;
border: 1px dashed rgb(34,70,79);
}
.tornadowarningBox {
color: white;
font-size: 13px;
text-align: center;
background-color: #CC0000;
margin: 0 0 0 0;
padding: .5em 0em .5em 0em;
border: 1px dashed rgb(255,255,255);
}