Trying to convert times such as - 215pm or 2:15 am or whatever to a 14:15 or 02:15 type string. (I am NOT using a TIME format for reasons to tedious to go into.)
Have managed to get an array output that contains hours, minutes and am/pm (but only if characters are present).
I want to allow erroneous characters through so I can EXPLICITLY fire an error message but a) I cannot get a "simple" OR test to work and b) strtolower
is not working for me - I don't know why.
$hour= $matches['h'];
$minute=$matches['m'];
if(!array_key_exists('ap', $matches)){$matches ['ap'] ="am";};
$ampm=$matches['ap'];
strtolower ($ampm);
debug ($hour,"hr");
debug ($minute,"min");
debug ($ampm,"ampm");
if ($ampm=="am" or $ampm=="pm") {echo "fine";}; // ALWAYS TRUE
if ($ampm==="am" or $ampm==="pm") {echo "fine";}; // FAILS WITH UPPER CASE AM AND PM
if ($hour<12 and $ampm=="pm") {$hour = $hour+12;};
debug ($hour,"hr");
debug ($minute,"min");
debug ($ampm,"ampm");
So I do not understand why the simple string test $ampm=="am" or $ampm=="pm"
is always true but that is just academic. But I REALLY do not understand why strtolower
does not change "AM" to "am" so that I cannot even use a ===
congruence test.
Any thoughts?