Skip to content

Instantly share code, notes, and snippets.

@halles
Created May 13, 2013 21:39
Show Gist options
  • Save halles/5571750 to your computer and use it in GitHub Desktop.
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.
<?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