function receitaok($cpf) {
// Checa a situa��o de um CPF
// Recebe: o cpf em uma string sem pontos ou tracos
// Retorna um array com dois campos
//     i) Se o CPF � inv�lido retorna {$cpf,"CPF INCORRETO"
//     ii)Caso contr�rio retorna {NOME, STATUS }
   $cpf = substr($cpf,0,3).".".substr($cpf,3,3).".". 
          substr($cpf,6,3)."-".substr($cpf,9,2);

        $fp=fopen("http://www.receita.fazenda.gov.br/Scripts/srf/cpf/cpf2000.dll
?Consultar&CPF=$cpf&indAutoatend=0","r");

        while ($buf=fgets($fp,4096) ) {
                if ( strpos($buf,"CPF incorreto!" ) )
                        return array($cpf,"CPF incorreto");
                if ( strpos($buf,$cpf) ) {
                        $buf=fgets($fp,4096);
                        $nome=striphtml(substr(fgets($fp,4096),19));
                        $buf=fgets($fp,4096);
                        $situ=striphtml(substr(fgets($fp,4096),19));
                        break;
                }
        }
        return array($nome,$situ);
}
function striphtml($str) {
$search = array ("'<script[^>]*?>.*?</script>'si",  
                 "'<[\/\!]*?[^<>]*?>'si",           
                 "'([\r\n])[\s]+'",                 
                 "'&(quot|#34);'i",                 
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "'&(iexcl|#161);'i",
                 "'&(cent|#162);'i",
                 "'&(pound|#163);'i",
                 "'&(copy|#169);'i",
                 "'&#(\d+);'e");                    



$replace = array ("",
                  "",
                  "\\1",
                  "\"",
                  "&",
                  "<",
                  ">",
                  " ",
                  chr(161),
                  chr(162),
                  chr(163),
                  chr(169),
                  "chr(\\1)");

 return preg_replace ($search, $replace, $str);
}