This paper mainly introduces the function of verifying the identity card of PHP. Have a good reference value, follow the small series together to see it
If you don't say much, look at the code:
function Is_idcard ($id) {$id = Strtoupper ($id); $REGX = "/(^\d{15}$) | (^\d{17} ([0-9]| X) $)/"; $arr _split = Array (); if (!preg_match ($REGX, $id)) {return FALSE; } if (15==strlen ($id))//Check 15-bit {$regx = "/^ (\d{6}) + (\d{2}) + (\d{2}) + (\d{2}) + (\d{3}) $/"; @preg_match ($REGX, $id, $arr _split); Check that the birthday date is correct $dtm _birth = "+". $arr _split[2]. '/' . $arr _split[3]. '/'. $arr _split[4]; if (!strtotime ($dtm _birth)) {return FALSE; } else {return TRUE; }} else//check 18-bit {$regx = "/^ (\d{6}) + (\d{4}) + (\d{2}) + (\d{2}) + (\d{3}) ([0-9]| X) $/"; @preg_match ($REGX, $id, $arr _split); $dtm _birth = $arr _split[2]. '/' . $arr _split[3]. '/'. $arr _split[4]; if (!strtotime ($dtm _birth))//Check whether the birthday date is correct {return FALSE; } else {//verify that the check code for the 18-bit ID is correct. The check digit is generated according to ISO 7064:1983.mod 11-2, and X can be considered the number 10. $arr _int = Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); $arr _ch = Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', '2 '); $sign = 0; for ($i = 0; $i < $i + +) {$b = (int) $id {$i}; $w = $arr _int[$i]; $sign + = $b * $W; } $n = $sign% 11; $val _num = $arr _ch[$n]; if ($val _num! = substr ($id, 1)) {return FALSE; } else {return TRUE; } } }}
The above is the whole content of this article, I hope that everyone's study has helped.