Just look at the code, it's a simple PHP class
Copy Code code as follows:
<?php
$IDCard = new Idcard ();
Var_dump ($IDCard:: Iscard ($_get[' card '));
/**
* ID card processing class
*/
class Idcard {
//Check ID card is correct
public static function Iscard ($card) {
$card = Self::to18card ($card);
if (strlen ($card)!= 18) {
return false;
}
$cardBase = substr ($card, 0, 17);
Return (Self::getverifynum ($cardBase) = = Strtoupper (substr ($card, 17, 1));
}
//Format 15-digit ID number is 18-bit
public static function To18card ($card) {
$card = Trim ($card);
if (strlen ($card) = = 18) {
return $card;
}
if (strlen ($card)!= 15) {
return false;
}
If the ID card sequence code is 996 997 998 999, these are special codes for centenarians and
if (Array_search substr ($card, 3), Array (' 996 ', ' 997 ', ' 998 ', ' 999 '))!== false) {
$card = substr ($card, 0, 6). ' 18 '. SUBSTR ($card, 6, 9);
} else {
$card = substr ($card, 0, 6). ' 19 '. SUBSTR ($card, 6, 9);
}
$card = $card. Self::getverifynum ($card);
return $card;
}
//Calculate ID Check code, according to national standard GB 11643-1999
private static function Getverifynum ($cardBase) {
if (strlen ($cardBase)!= 17) {
return false;
}
//Weighting factor
$factor = Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
//check code corresponding value
$verify _number_list = Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 ');
$checksum = 0;
for ($i = 0; $i < strlen ($cardBase); $i + +) {
$checksum + + substr ($cardBase, $i, 1) * $factor [$i];
}
$mod = $checksum% 11;
$verify _number = $verify _number_list[$mod];
return $verify _number;
}
}
?>
In addition, the verification of the identity card number of the site also provides identity card attribution of the query tools are as follows:
Http://tools.jb51.net/bianmin/sfz