| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_apps/dialogo/application/lib/correios/ |
Upload File : |
<?php
require_once('phpQuery.php');
/**
* Class Correios
* Traz endereço do cep usando site dos correios
* @package Bleez\Correios\Model\Endereco
*/
class Correios
{
/**
* @param string $cep
* @return array|bool
*/
public static function getEndereco($cep)
{
$html = self::_request('http://m.correios.com.br/movel/buscaCepConfirma.do', array(
'cepEntrada' => $cep,
'tipoCep' => '',
'cepTemp' => '',
'metodo' => 'buscarCep'
));
if($html && strpos($html, 'Error') === false && strpos($html, 'Dados nao encontrados') === false){
$phpQuery = phpQuery::newDocumentHTML($html, $charset = 'utf-8');
$dados = array(
'address'=> trim($phpQuery->find('.caixacampobranco .resposta:contains("Logradouro: ") + .respostadestaque:eq(0)')->html()),
'neighborhood'=> trim($phpQuery->find('.caixacampobranco .resposta:contains("Bairro: ") + .respostadestaque:eq(0)')->html()),
'city/state'=> trim($phpQuery->find('.caixacampobranco .resposta:contains("Localidade / UF: ") + .respostadestaque:eq(0)')->html()),
'zip'=> trim($phpQuery->find('.caixacampobranco .resposta:contains("CEP: ") + .respostadestaque:eq(0)')->html())
);
if(empty($dados['city/state'])){
return false;
}
$dados['city/state'] = explode('/',$dados['city/state']);
$dados['state'] = trim($dados['city/state'][1]);
$dados['city'] = trim($dados['city/state'][0]);
unset($dados['city/state']);
if(strpos($dados['address'], ' - ') !== false){
$l = explode(' - ', $dados['address']);
$dados['address'] = $l[0];
}
$dados['address'] = $dados['address'];
return $dados;
}
return false;
}
/**
* @param string $url
* @param array $post
* @param array $get
* @return mixed
*/
public static function _request($url, $post=array(), $get=array())
{
$url = explode('?',$url,2);
if(count($url)===2){
$temp_get = array();
parse_str($url[1],$temp_get);
$get = array_merge($get,$temp_get);
}
$ch = curl_init($url[0]."?".http_build_query($get));
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return curl_exec($ch);
}
}