Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Formatação de dados - Brasil
function formataCEP($cep)
{
$valor = str_replace(array('.','-',','),'',trim($cep));
$tam = strlen($valor);
if($tam == 8)
{
$p1 = substr($valor,0,5);
$p2 = substr($valor,5,3);
$resultado = $p1."-".$p2;
}
else
{
$resultado = "";
}
return $resultado;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.