| 1 : |
|
|
<?php |
| 2 : |
|
|
/* |
| 3 : |
|
|
* Created on 16/Dez/2005 |
| 4 : |
|
|
* |
| 5 : |
|
|
* funções para geração automática |
| 6 : |
|
|
* e randômica de CPFs e CNPJs |
| 7 : |
|
|
*/ |
| 8 : |
|
|
|
| 9 : |
|
|
|
| 10 : |
|
|
|
| 11 : |
|
|
|
| 12 : |
|
|
function mod($dividendo,$divisor) |
| 13 : |
|
|
{ |
| 14 : |
|
|
return round($dividendo - (floor($dividendo/$divisor)*$divisor)); |
| 15 : |
|
|
} |
| 16 : |
|
|
|
| 17 : |
|
|
function cpf($compontos) |
| 18 : |
|
|
{ |
| 19 : |
|
|
$n1 = rand(0,9); |
| 20 : |
|
|
$n2 = rand(0,9); |
| 21 : |
|
|
$n3 = rand(0,9); |
| 22 : |
|
|
$n4 = rand(0,9); |
| 23 : |
|
|
$n5 = rand(0,9); |
| 24 : |
|
|
$n6 = rand(0,9); |
| 25 : |
|
|
$n7 = rand(0,9); |
| 26 : |
|
|
$n8 = rand(0,9); |
| 27 : |
|
|
$n9 = rand(0,9); |
| 28 : |
|
|
$d1 = $n9*2+$n8*3+$n7*4+$n6*5+$n5*6+$n4*7+$n3*8+$n2*9+$n1*10; |
| 29 : |
|
|
$d1 = 11 - ( mod($d1,11) ); |
| 30 : |
|
|
if ( $d1 >= 10 ) |
| 31 : |
|
|
{ $d1 = 0 ; |
| 32 : |
|
|
} |
| 33 : |
|
|
$d2 = $d1*2+$n9*3+$n8*4+$n7*5+$n6*6+$n5*7+$n4*8+$n3*9+$n2*10+$n1*11; |
| 34 : |
|
|
$d2 = 11 - ( mod($d2,11) ); |
| 35 : |
|
|
if ($d2>=10) { $d2 = 0 ;} |
| 36 : |
|
|
$retorno = ''; |
| 37 : |
|
|
if ($compontos==1) {$retorno = ''.$n1.$n2.$n3.".".$n4.$n5.$n6.".".$n7.$n8.$n9."-".$d1.$d2;} |
| 38 : |
|
|
else {$retorno = ''.$n1.$n2.$n3.$n4.$n5.$n6.$n7.$n8.$n9.$d1.$d2;} |
| 39 : |
|
|
return $retorno; |
| 40 : |
|
|
} |
| 41 : |
|
|
|
| 42 : |
|
|
function cnpj($compontos) |
| 43 : |
|
|
{ |
| 44 : |
|
|
$n1 = rand(0,9); |
| 45 : |
|
|
$n2 = rand(0,9); |
| 46 : |
|
|
$n3 = rand(0,9); |
| 47 : |
|
|
$n4 = rand(0,9); |
| 48 : |
|
|
$n5 = rand(0,9); |
| 49 : |
|
|
$n6 = rand(0,9); |
| 50 : |
|
|
$n7 = rand(0,9); |
| 51 : |
|
|
$n8 = rand(0,9); |
| 52 : |
|
|
$n9 = 0; |
| 53 : |
|
|
$n10= 0; |
| 54 : |
|
|
$n11= 0; |
| 55 : |
|
|
$n12= 1; |
| 56 : |
|
|
$d1 = $n12*2+$n11*3+$n10*4+$n9*5+$n8*6+$n7*7+$n6*8+$n5*9+$n4*2+$n3*3+$n2*4+$n1*5; |
| 57 : |
|
|
$d1 = 11 - ( mod($d1,11) ); |
| 58 : |
|
|
if ( $d1 >= 10 ) |
| 59 : |
|
|
{ $d1 = 0 ; |
| 60 : |
|
|
} |
| 61 : |
|
|
$d2 = $d1*2+$n12*3+$n11*4+$n10*5+$n9*6+$n8*7+$n7*8+$n6*9+$n5*2+$n4*3+$n3*4+$n2*5+$n1*6; |
| 62 : |
|
|
$d2 = 11 - ( mod($d2,11) ); |
| 63 : |
|
|
if ($d2>=10) { $d2 = 0 ;} |
| 64 : |
|
|
$retorno = ''; |
| 65 : |
|
|
if ($compontos==1) {$retorno = ''.$n1.$n2.".".$n3.$n4.$n5.".".$n6.$n7.$n8."/".$n9.$n10.$n11.$n12."-".$d1.$d2;} |
| 66 : |
|
|
else {$retorno = ''.$n1.$n2.$n3.$n4.$n5.$n6.$n7.$n8.$n9.$n10.$n11.$n12.$d1.$d2;} |
| 67 : |
|
|
return $retorno; |
| 68 : |
|
|
} |
| 69 : |
|
|
|
| 70 : |
|
|
|
| 71 : |
|
|
|
| 72 : |
|
|
|
| 73 : |
|
|
?> |
| 74 : |
|
|
|
| 75 : |
|
|
|