Skip to content

Instantly share code, notes, and snippets.

@mlask
Created September 23, 2014 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlask/4e80ec890f5546813f48 to your computer and use it in GitHub Desktop.
Save mlask/4e80ec890f5546813f48 to your computer and use it in GitHub Desktop.
Weryfikacja numeru Dowodu Osobistego
<?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