PHP code example of andredebrito / phpviacep

1. Go to this page and download the library: Download andredebrito/phpviacep 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/ */

    

andredebrito / phpviacep example snippets




use AndreDeBrito\PHPViaCep\PhpViaCep;

$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->json()->fetch()
	      ->jsonToObject();

var_dump($findByCep->getResponse());

$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->xml()
	      ->fetch();

var_dump($findByCep->getResponse());

$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->piped()
	      ->fetch();

var_dump($findByCep->getResponse());

$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->querty()
	      ->fetch();

var_dump($findByCep->getResponse());



use AndreDeBrito\PHPViaCep\PhpViaCep;

$findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")
		  ->json()
		  ->fetch()
		  ->jsonToObject();

var_dump($findByAddress->getResponse());

$findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")
		  ->xml()
		  ->fetch();

var_dump($findByAddress->getResponse());

if($findByAddress->getError()){
    echo $findByAddress->getError();
}