<?php /* Versoes de Referencias 2.0;3.0;301;3.2 Modificado por Felipe Jorge L. Rabelo Ferreira 23/04/2005 */ $cpf="123456-09"; $cpf = ereg_replace("[^0-9]", "", $cpf); if (strlen($cpf)!=11) echo "CPF INVALIDO"; else { $dv = substr($cpf,-2); $compdv = 0; $nulos = array("12345678909","11111111111","22222222222","33333333333", "44444444444","55555555555","66666666666","77777777777", "88888888888","99999999999","00000000000"); if(in_array($cpf, $nulos)) echo "CPF NULO"; else { $acum=0; for ($i=0; $i<9; $i++) $acum+=$cpf[$i]*(10-$i); $x=$acum % 11; $acum = ($x>1) ? (11 - $x) : 0; $compdv = $acum * 10; $acum=0; for ($i=0; $i<10; $i++) $acum+=$cpf[$i]*(11-$i); $x=$acum % 11; $acum = ($x>1) ? (11 - $x) : 0; $compdv = $compdv + $acum; if($compdv == $dv) echo "CPF VALIDO"; else echo "CPF INVALIDO"; } } ?>