redenumire functie cui
[validatoare.git] / php / cui.php
blob:a/php/cui.php -> blob:b/php/cui.php
--- a/php/cui.php
+++ b/php/cui.php
@@ -1,30 +1,30 @@
-<?php 
+<?php
+
+function verificaCui ($cif) {
+	if ( !is_numeric ($cif) ) return false;
+	if ( strlen ($cif)>10 ) return false;
+	$cifra_control = substr ($cif, -1);
+	$cif = substr ($cif, 0, -1);
+	while (strlen ($cif)!=9) {
+		$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 = $suma*10;
+	$rest = fmod ($suma, 11);
+	if ( $rest == 10 ) $rest = 0;
+	if ( $rest == $cifra_control ) {
+		return true;
+	} else {
+		return false;
+	}
+}
 
 $cui = "2864518";
 
 if ( verificaCui ( $cui ) ) {
-    echo $cui." e valid";
+	echo $cui." e valid";
 } else {
-    echo $cui." e invalid";
-}
-
-function verificaCui ($cif) {
-    if (!is_numeric($cif)) return false;
-    if ( strlen($cif)>10 ) return false;
-    $cifra_control=substr($cif, -1);
-    $cif=substr($cif, 0, -1);
-    while (strlen($cif)!=9){
-        $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=$suma*10;
-    $rest=fmod($suma, 11);
-    if ( $rest==10 ) $rest=0;
-    if ( $rest == $cifra_control ) {
-        return true;
-    } else {
-        return false;
-    }
+	echo $cui." e invalid";
 }
 
 ?>

comments