Created
September 23, 2014 13:04
-
-
Save mlask/4e80ec890f5546813f48 to your computer and use it in GitHub Desktop.
Weryfikacja numeru Dowodu Osobistego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function check_do_number ($number) | |
{ | |
$t = 0; | |
$n = array(); | |
$w = array(7, 3, 1); | |
if (!preg_match('/^([A-Z]+)(\d{1})(\d+)$/', strtoupper($number), $n)) return false; | |
foreach (str_split($n[1] . $n[3]) as $i => $l) | |
$t += $w[$i % 3] * (is_numeric($l) ? $l : (ord($l) - 55)); | |
return ($t % 10) == (int)$n[2] ? true : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment