Created
May 13, 2013 21:39
-
-
Save halles/5571750 to your computer and use it in GitHub Desktop.
Función para Sanitizar RUT Chile (Añade puntos, guiones y convierte la k a mayúsucula en caso de no serlo.
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 sanitizarRut($rut){ | |
$temp = explode('-',$rut); | |
if (!isset($temp[1]) || $temp[1] == ''){ | |
$temp[0] = substr($rut,0,strlen($rut)-1); | |
$temp[1] = substr($rut,strlen($rut)-1); | |
} | |
$digito_v = $temp[1]; | |
$digito_v = ($digito_v=='k')?'K':$digito_v; | |
$rut = str_replace(array('.',',',' '),'',$temp[0]); | |
if(!is_numeric($rut)) $rut = 0; | |
return number_format($rut, 0, ',', '.').'-'.$digito_v; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment