Hello, I have a small script that depending on the title of the div the background has a different color. This use to work fine but, all of a sudden it just shows the color of the first case statement in the switch. Any suggestions what might be causing this?
The title are based from an RSS feed that is parsed just for a little background on what is displayed and when.
As you can see from the screen shot, this should be greenish color but, it is showing red and is taking the color of the first case. I tested this by removing the first one and then it shows yellow which is the second one. So that is how I determined it is not going down the line to display the correct color for the correct title. It is just stopping at the first title regardless if it is correct and just showing the first color.
//Set path to data file
#$data = "http://alerts.weather.gov/cap/".$zone.".atom";
$data = "http://alerts.weather.gov/cap/wwaatmget.php?x=".$zone."&y=1";
## End Configurable data ##
$alertColor = ' ';
$alertText = '#FFF';
// get path info & protect for cross-site scripting vulnerability
$sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : '';
// Lets parse the feed
$dom = new DOMDocument();
$dom->load($data);
$events = [];
foreach ($dom->getElementsByTagNameNS("urn:oasis:names:tc:emergency:cap:1.1", "event") as $event) {
$events[] = $event->nodeValue;
}
$alertValues = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement');
$events = array_intersect($alertValues, $events);
// Set the alert colors for the banner background
switch(TRUE)
{
case 'Tornado Warning':
$alertColor = 'rgba(255, 0, 0, 0.4)';
break;
case 'Severe Thunderstorm Warning':
$alertColor = 'rgba(255, 165, 0, 0.4)';
break;
case 'Tornado Watch':
$alertColor = 'rgba(255, 255, 0, 0.4)';
break;
case 'Severe Thunderstorm Watch':
$alertColor = 'rgba(219, 112, 147, 0.4)';
break;
case 'Flash Flood Warning':
$alertColor = 'rgba(139, 0, 0, 0.4)';
break;
case 'Flash Flood Watch':
$alertColor = 'rgba(46, 139, 87, 0.4)';
break;
case 'Flood Warning':
$alertColor = 'rgba(0, 255, 0, 0.4)';
break;
case 'Flood Watch':
$alertColor = 'rgba(46, 139, 87, 0.4)';
break;
case 'Flood Advisory':
$alertColor = 'rgba(0, 255, 127, 0.4)';
break;
case 'Winter Storm Warning':
$alertColor = 'rgba(255, 105, 180, 0.4)';
break;
case 'Winter Storm Watch':
$alertColor = 'rgba(70, 130, 180, 0.4)';
break;
case 'Winter Weather Advisory':
$alertColor = 'rgba(123, 104, 238, 0.4)';
break;
case 'Special Weather Statement':
$alertColor = 'rgba(255, 228, 181, 0.4)';
}
// Lets assign some styles for the banner
$bannerStyle = '"color:' . $alertText . '; width:100%; border-top-style:solid; border-bottom-style:solid; border-color:#FFF; border-width:1px; font-size:12px; text-shadow: 0 1px 1px #111; font-weight:700; font-family: Arial,Helvetica,sans-serif; text-align: center; background-color:' . $alertColor . '; margin-bottom:5px; padding: .2em 0em .2em 0em"';
// Lets assembly the banners to display
foreach ($events as $message) {
echo '<div style=' . $bannerStyle . '>
<strong>WEATHER BROADCAST ALERT - ' . $message . '</strong>... Listen now to our LIVE NOAA Weather Radio Stream <a href=" ' . $feed . '" class="NWRLink" onclick="return popup(this, \'noaa\')" title="Live NOAA Radio For Dallas County">[Click here to listen]</a>
</div>';
}