Last active
March 8, 2022 15:57
-
-
Save ricardodbv/3881019 to your computer and use it in GitHub Desktop.
Revisions
-
ricardodbv revised this gist
Apr 9, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php /** * Comprueba si el rut ingresado es valido * -
ricardodbv created this gist
Oct 12, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ /** * Comprueba si el rut ingresado es valido * * @param $rut string * @return true o false */ function valida_rut($rut) { $rut = preg_replace('/[^k0-9]/i', '', $rut); $dv = substr($rut, -1); $numero = substr($rut, 0, strlen($rut)-1); $i = 2; $suma = 0; foreach(array_reverse(str_split($numero)) as $v) { if($i==8) $i = 2; $suma += $v * $i; ++$i; } $dvr = 11 - ($suma % 11); if($dvr == 11) $dvr = 0; if($dvr == 10) $dvr = 'K'; if($dvr == strtoupper($dv)) return true; else return false; }