Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

23.3. 身份證校驗

		
<?php 

function check_id_number($no){
	if (strlen($no) != 18){
		return false;
	}
	$sigma = 0;
	$wi = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); 
	$ai = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); 
	for ($i = 0;$i < 17;$i++) { 
	    $sigma += ((int) $no{$i}) * $wi[$i]; 
	}
	
	if (substr($no,17) == $ai[($sigma % 11)]){	
		return true;
	}else{
		return false; 
	}
}

echo check_id_number('330702198003090915');