阿科
|
分享:
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重新編輯 ]
|