Help with If...Elseif...
Posted: Sat Jun 05, 2004 6:53 pm
Hope some of the fellow php scripters can lend me a hand...
I'm playing around with displaying the current homeland security threat level, but I am running into issues. I can pull down the xml file, stip it, and then display the current status, but I want to take what the status is and then add some things to it. But I can't this to work. All I get is just an error message that I put in there incase nothing happened. I am sure I am doing something wrong with the If statements.
It will print the current threat (print $threat), but then it will just print out the error message on the last else statement. Its not seeing the statements...
Anybody want to chime in on this?
Cheers,
Tweak
I'm playing around with displaying the current homeland security threat level, but I am running into issues. I can pull down the xml file, stip it, and then display the current status, but I want to take what the status is and then add some things to it. But I can't this to work. All I get is just an error message that I put in there incase nothing happened. I am sure I am doing something wrong with the If statements.
Code: Select all
<?php
$threat = eregi_replace('.*CONDITION="(.*)" />', '1', implode('\n', file("http://www.dhs.gov/dhspublic/getAdvisoryCondition")));
$low = "LOW";
$guarded = "GUARDED";
$elevated = "ELEVATED";
$high = "HIGH";
$severe = "SEVERE";
print $threat;
if ($threat == $low) {
$ccode = "Green (low risk of terrorist attacks)";
$fixcase = ucwords(strtolower($threat)); //fixes the UPPER case issue
$newthreat = $fixcase;
print "Homeland Security Threat Level is $newthreat; condition is code $ccode";
} elseif ($threat == $guarded) {
$ccode = "Blue (general risk of terrorist attacks)";
$fixcase = ucwords(strtolower($threat)); //fixes the UPPER case issue
$newthreat = $fixcase;
print "Homeland Security Threat Level is $newthreat; condition is code $ccode";
} elseif ($threat == $elevated) {
$ccode = "Yellow (significant risk of terrorist attacks)";
$fixcase = ucwords(strtolower($threat)); //fixes the UPPER case issue
$newthreat = $fixcase;
print "Homeland Security Threat Level is $newthreat; condition is code $ccode";
} elseif ($threat == $high) {
$ccode = "Orange (high risk of terrorist attacks)";
$fixcase = ucwords(strtolower($threat)); //fixes the UPPER case issue
$newthreat = $fixcase;
print "Homeland Security Threat Level is $newthreat; condition is code $ccode";
} elseif ($threat == $severe) {
$ccode = "Red (severe risk of terrorist attacks)";
$fixcase = ucwords(strtolower($threat)); //fixes the UPPER case issue
$newthreat = $fixcase;
print "Homeland Security Threat Level is $newthreat; condition is code $ccode";
} else {
print "Error getting level from dhs.gov";
}
?>Anybody want to chime in on this?
Cheers,
Tweak