From 6b9c8980522f1dbdd200f39856bcba7887decc0d Mon Sep 17 00:00:00 2001 From: Eriksen Costa Paixão Date: Thu, 3 Sep 2009 06:21:36 +0000 Subject: [PATCH] by Eriksen: Corrigido função de formatação para CEPs que comecem com 0 --- ieducar/intranet/include/funcoes.inc.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/ieducar/intranet/include/funcoes.inc.php b/ieducar/intranet/include/funcoes.inc.php index c95e80d..422665c 100755 --- a/ieducar/intranet/include/funcoes.inc.php +++ b/ieducar/intranet/include/funcoes.inc.php @@ -96,17 +96,22 @@ return substr( $str, 0, 2 ) . "." . substr( $str, 2, 3 ). "." . substr( $str, 5, 3 ) . "/" . substr( $str, 8, 4 ) . "-" . substr( $str, 12, 2 ); } - function int2CEP( $int ) - { - if( $int ) - { - return substr( $int, 0, 5 ) . "-" . substr( $int, 5, 3 ); - } - else - { - return ""; - } - } + /** + * Formata um valor numérico em uma representação string de CEP. + * + * @param string|int $int + * @return string + */ + function int2CEP($int) + { + if ($int) { + $int = (string) str_pad($int, 8, '0', STR_PAD_LEFT); + return substr($int, 0, 5) . '-' . substr($int, 5, 3); + } + else { + return ''; + } + } function limpa_acentos( $str_nome ) { -- libgit2 0.21.2