Skip to content

Instantly share code, notes, and snippets.

@brunokunace
Created July 25, 2018 16:50
Show Gist options
  • Save brunokunace/8f8bf21a9ea34222a79e4cb0cd2e5817 to your computer and use it in GitHub Desktop.
Save brunokunace/8f8bf21a9ea34222a79e4cb0cd2e5817 to your computer and use it in GitHub Desktop.
<?php
class Address {
public function get_address($cep)
{
$url = "http://viacep.com.br/ws/".$cep."/xml";
return simplexml_load_file($url);
}
}
<?php
require('classes/Address.php');
$address = new Address();
$cep = "36204-220";
$newAddress = $address->get_address($cep);
echo "CEP Informado: ".$cep."<br />";
echo "Rua:".$newAddress->logradouro."<br />";
echo "Bairro:".$newAddress->bairro."<br />";
echo "Estado:".$newAddress->uf."<br />";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment