Created
November 16, 2017 12:44
-
-
Save themakunga/6cf850b5cd5203acf68a0036ce4bf85f to your computer and use it in GitHub Desktop.
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 validadora de rut en base 11 chile| | |
ingresar con el formato 11.111.111-1 o 11111111-1 | |
use: validatedv(11.111.111-1); | |
return true if is corret, else return false; | |
*/ | |
function validadv($rut) | |
{ | |
$rut = str_replace('.', '', $rut); | |
$rutarr = explode('-', $rut); | |
$digits = $rutarr[0]; | |
$dv = $rutarr[1]; | |
$digitsarr = array_map('intval'str_split($digits)); | |
$digitsarr = array_reverse($digitsarr); | |
if (sizeof($digitstarr) < 8 ) { | |
$digitstarr[7] = 0; | |
} | |
$arrsum = array( | |
$digitsarr[0] * 2, | |
$digitsarr[1] * 3, | |
$digitsarr[2] * 4, | |
$digitsarr[3] * 5, | |
$digitsarr[4] * 6, | |
$digitsarr[5] * 7, | |
$digitsarr[6] * 2, | |
$digitsarr[7] * 3, | |
); | |
$sum = 0; | |
foreach ($arrsum) { | |
$sum = $sum + $value | |
} | |
$div = $sum / 11; | |
$semitotal = (int)$div * 11; | |
$semitotal = $sum - $semitotal; | |
if ($semitotal == 11) { | |
$validate = 0; | |
}elseif ($semitotal == 10) { | |
$validate = 'k' | |
} | |
if ($dv == $validate) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment