PHP code example of engfabiodesalvi / busca-cep-php

1. Go to this page and download the library: Download engfabiodesalvi/busca-cep-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

engfabiodesalvi / busca-cep-php example snippets





gfabiodesalvi\BuscaCepPhp\Search;

$busca = new Search;

// Busca o CEP
$resultado = $busca->getAdressFromZipcode('01001000');

print_r($resultado);


use Engfabiodesalvi\BuscaCepPhp\CepSearch;

$cep = new CepSearch();

$address = $cep->search('01001000');

echo $address->street();

use Engfabiodesalvi\BuscaCepPhp\CepSearch;

$search = new CepSearch();

$address = $search->search('01001000');

echo "CEP........: ".$address->cep().PHP_EOL;
echo "Logradouro.: ".$address->street().PHP_EOL;
echo "Bairro.....: ".$address->district().PHP_EOL;
echo "Cidade.....: ".$address->city().PHP_EOL;
echo "Estado.....: ".$address->state().PHP_EOL;
echo "IBGE.......: ".$address->ibge().PHP_EOL;
echo "Provider...: ".$address->provider().PHP_EOL;

use Engfabiodesalvi\BuscaCepPhp\Infrastructure\Config\Config;

Config::set(
    'cepaberto_token',
    getenv('CEPABERTO_TOKEN')
);

Config::set(
    'cepaberto_token',
    getenv('CEPABERTO_TOKEN')
);

$logger = new ConsoleLogger();

$search = new CepSearch(logger: $logger);

try {

    $address = $search->search('01001000');

} catch (ProviderException $e) {

    echo $e->getMessage();

}
bash
composer