Created
July 25, 2018 16:47
-
-
Save brunokunace/4621114282681aa35883fa0610753a1f to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Address { | |
public $bairro; | |
public $logradouro; | |
public $uf; | |
public function get_address($cep) | |
{ | |
$url = "http://viacep.com.br/ws/".$cep."/xml"; | |
$xml = simplexml_load_file($url); | |
$this->bairro = $xml->bairro; | |
$this->logradouro = $xml->logradouro; | |
$this->uf = $xml->uf; | |
} | |
} |
This file contains 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 | |
require('classes/Address.php'); | |
$address = new Address(); | |
$cep = "36204-220"; | |
$address->get_address($cep); | |
echo "CEP Informado: ".$cep."<br />"; | |
echo "Rua:".$address->logradouro."<br />"; | |
echo "Bairro:".$address->bairro."<br />"; | |
echo "Estado:".$address->uf."<br />"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment