time "24:14"
is not valid time and this should be "00:14"
for correct valid time but strtotime
return CORRECT
and its wrong.
if(strtotime("24:14")) {
echo "CORRECT<br/>";
} else {
echo "NOT CORRECT<br/>";
}
time "24:14"
is not valid time and this should be "00:14"
for correct valid time but strtotime
return CORRECT
and its wrong.
if(strtotime("24:14")) {
echo "CORRECT<br/>";
} else {
echo "NOT CORRECT<br/>";
}
You're confused.
strtotime doesn't return true or false. it returns a timestamp, which is a truthy value or false on error.
quoting from the manual:
Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.
Reference -- http://php.net/manual/en/function.strtotime.php
Because it returns false on error, you need to compare it to false
if(strtotime("24:14") !== false) {
//Correct
} else {
//Not correct
}
strtotime uses standard PHP time format. As you can see here "24" is a valid string for hours from PHP 5.3.0.
You can use a regex to check that time, for example:
function time_check($t) {
$reg = '/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/';
if ( preg_match($reg, $t) )
echo "CORRENT\n";
else
echo "WRONG\n";
}
$check_ok = "01:22";
$check_no = "24:11";
time_check($check_ok);
time_check($check_no);