redenumire functie cui
[validatoare.git] / php / cui.php
blob:a/php/cui.php -> blob:b/php/cui.php
<?php <?php
   
function isCui ($cif) { $cui = "2864518";
   
  if ( verificaCui ( $cui ) ) {
  echo $cui." e valid";
  } else {
  echo $cui." e invalid";
  }
   
  function verificaCui ($cif) {
if (!is_numeric($cif)) return false; if (!is_numeric($cif)) return false;
if ( strlen($cif)>10 ) return false; if ( strlen($cif)>10 ) return false;
$cifra_control=substr($cif, -1); $cifra_control=substr($cif, -1);
$cif=substr($cif, 0, -1); $cif=substr($cif, 0, -1);
while (strlen($cif)!=9){ while (strlen($cif)!=9){
$cif='0'.$cif; $cif='0'.$cif;
} }
$suma=$cif[0] * 7 + $cif[1] * 5 + $cif[2] * 3 + $cif[3] * 2 + $cif[4] * 1 + $cif[5] * 7 + $cif[6] * 5 + $cif[7] * 3 + $cif[8] * 2; $suma=$cif[0] * 7 + $cif[1] * 5 + $cif[2] * 3 + $cif[3] * 2 + $cif[4] * 1 + $cif[5] * 7 + $cif[6] * 5 + $cif[7] * 3 + $cif[8] * 2;
$suma=$suma*10; $suma=$suma*10;
$rest=fmod($suma, 11); $rest=fmod($suma, 11);
if ( $rest==10 ) $rest=0; if ( $rest==10 ) $rest=0;
if ( $rest == $cifra_control ) { if ( $rest == $cifra_control ) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
   
?> ?>
comments