阿科
|
分享:
x0
|
[PHP][教学] 身份证验证(转载自 小数点 多次元论坛)
使用时只要 include 这个 mytools.php 档, 然后呼叫 check_roc_id($id), 并传入身份证字号, 如果传回 0 表示这个身分证字号是正确的, 传回其他非 0 的数值, 则表示字号有错误.... <? //mytools.php function check_roc_id($roc_id) { $id_head = array( 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'J' => 18, 'K' => 19, 'L' => 20, 'M' => 21, 'N' => 22, 'P' => 23, 'Q' => 24, 'R' => 25, 'S' => 26, 'T' => 27, 'U' => 28, 'V' => 29, 'W' => 30, 'X' => 31, 'Y' => 32, 'Z' => 33, 'I' => 34, 'O' => 35);
$n0 = $id_head[strtoupper(substr($roc_id, 0, 1))]; $n[] = Ɔ' $n[] = substr($n0, 0, 1); $n[] = substr($n0, 1, 1);
for ($lop1=1; $lop1<strlen($roc_id); $lop1++) { $n[] = substr($roc_id, $lop1, 1); }
return ( ($n[1] + ($n[2]*9) + ($n[3]* 8)+ ($n[4]*7) + ($n[5]*6) + ($n[6]*5) + ($n[7]*4) + ($n[8]*3) + ($n[9]*2) + $n[10] + $n[11]) % 10); }
?>
[ 此文章被andyz在2005-05-18 20:22重新编辑 ]
|