PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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";
}
?>
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...
I tired === and it didn't work, this is what it shows:
ELEVATED Error getting level from dhs.gov
The exact output of $threat is ELEVATED or what ever the current status is (LOW, GUARDED, ELEVATED, HIGH, or SEVERE is what will be returned).
I have a print at the top of the code just to make sure I am hitting the xml file, its being stripped, and shows the status. The second part that is showing "error...blah" is on the last else statement.
I found that my problem was there was white space in the $threat, so I had to add trim() do it and that licked the issue. I was also point to use switch to compare the single vars.