function CheckNationalCode($code='')
{
$code = (string) preg_replace('/[^0-9]/','',$code);
if(strlen($code)>10 or strlen($code)<8)
return false;
$code = str_pad($code, 10, 0, STR_PAD_LEFT);
for($i=0; $i<10; $i++)
$blist[] = str_pad($i, 10, $i, STR_PAD_LEFT);
if(in_array($code, $blist))
return false;
$list_code = str_split($code);
$last = (int) $list_code[9];
unset($list_code[9]);
$i = 10;
$sum = 0;
foreach($list_code as $key=>$_)
{
$sum += intval($_) * $i;
$i--;
}
$mod =(int) $sum % 11;
if($mod >= 2)
$mod = 11 - $mod;
return $mod == $last;
}
$code = 1231234567;
if(CheckNationalCode($code))
echo 'ok';
else
echo 'err';