Skip to content

Instantly share code, notes, and snippets.

@lslucas
Created September 20, 2010 21:34
Show Gist options
  • Save lslucas/588695 to your computer and use it in GitHub Desktop.
Save lslucas/588695 to your computer and use it in GitHub Desktop.
<?php
/**
* Retorna todos os status do Correios para ID enviado
*
* @param string $id_correios ID do Correios
* @return array $array_retorno
*/
function status_correios( $id_correios ) {
$conteudo = file_get_contents('http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI='.$id_correios);
if ( empty($conteudo) ) return false;
$array_retorno = array();
preg_match_all( '/<tr>\s*<td[^>]*>(.*)<\/td>\s*<\/tr>/' , $conteudo , $array_regex );
if ( !is_array($array_regex) || count($array_regex) <= 0 ) return false;
foreach ( $array_regex[ 1 ] as $key => $linha ) {
$foo = explode( '</td><td>' , $linha );
if ( strip_tags( $foo[ 2 ] ) ) {
$array_retorno[] = array( strip_tags( $foo[ 0 ] ), strip_tags( $foo[ 1 ] ), strip_tags( $foo[ 2 ] ) );
}
}
return $array_retorno;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment