Jump to content

obtener el digito verificador del rut mediante php


Recommended Posts

codigo:

 


<?php

function getRut($rut){
$rut = strrev($rut);
$aux = 1;
for($i=0;$i<strlen($rut);$i++){
$aux++;
$s += intval($rut[$i])*$aux;
if($aux == 7){ $aux=1; }
}
$digit = 11-$s%11;
if($digit == 11){$d = 0;}elseif($digit == 10){$d = "K";}else{$d = $digit;}
return $d;
}

?>

 

lo unico que hace falta es llamar a la funcion con un rut como parametro

 

ejemplo

 

getRut(17594215)

 

y getRut te entregara el digito verificador del rut 17594215

Edited by cañangasñangas
Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...