Created
February 5, 2018 16:29
-
-
Save marcosnakamine/1a1cf7355f9789f48844dd9343399b8e to your computer and use it in GitHub Desktop.
PHP - Get information of brazilian CEP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cep = '17013021'; | |
$token = 'API_KEY'; | |
// Recebe o CEP | |
$curl = curl_init( 'http://www.cepaberto.com/api/v2/ceps.json?cep='.$cep ); | |
// Adiciona o token no cabeçalho | |
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Authorization: Token token="'.$token.'"' ) ); | |
// Não imprime na tela | |
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); | |
// Executa | |
$latlng = curl_exec( $curl ); | |
// Fecha pra economizar memória | |
curl_close( $curl ); | |
// Converte para Array | |
$latlng = json_decode( $latlng ); | |
echo 'ALTITUDE: '.$latlng->altitude; | |
echo '<br>'; | |
echo 'LATIDUDE: '.$latlng->latitude; | |
echo '<br>'; | |
echo 'LONGITUDE: '.$latlng->longitude; | |
echo '<br>'; | |
echo 'BAIRRO: '.$latlng->bairro; | |
echo '<br>'; | |
echo 'CEP: '.$latlng->cep; | |
echo '<br>'; | |
echo 'LOGRADOURO: '.$latlng->logradouro; | |
echo '<br>'; | |
echo 'CIDADE: '.$latlng->cidade; | |
echo '<br>'; | |
echo 'DDD: '.$latlng->ddd; | |
echo '<br>'; | |
echo 'IBGE: '.$latlng->ibge; | |
echo '<br>'; | |
echo 'ESTADO: '.$latlng->estado; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment