Created
July 2, 2014 15:24
-
-
Save marceloxp/fecade7dba56081329c6 to your computer and use it in GitHub Desktop.
Formatação de dados - Brasil
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
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