// 根据国家标准GB 11643-1999进行身份证有效校验
function isCard($card) {
if( strlen($card) != 18 ) {
return false;
}
$crad_id_base = substr($card, 0, 17);
$crad_id_verify = substr($card, -1);
// 加权因子
$factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3);
// 校验码对应值
$verify_number_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
$checksum = 0;
for( $i = 0; $i < strlen($crad_id_base); $i++ ) {
$checksum += substr($crad_id_base, $i, 1) * $factor[$i % 10];
}
$mod = $checksum % 11;
if( $crad_id_verify == $verify_number_list[$mod] ) {
return true;
}
return false;
}
(adsbygoogle = window.adsbygoogle || []).push({});
来源:https://www.02405.com/archives/1789