Following my code:
<?php
$test = 12;
$test2 = '1a';
$test3 = 1959;
echo checkdate((int)$test, (int)$test2, (int)$test3);
It's return true. Assuming that they are POST variable, how to solve it in the most faster way without a regex?
You are casting the values to check to valid values before checking if they are invalid. That's why you are getting true
as a result. That 1a
becomes 1
after you cast it to an int. Combined with the other date parts you get 12/01/1959 which is a valid date.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.