Commit 6b9c8980522f1dbdd200f39856bcba7887decc0d

Authored by Eriksen Costa Paixão
1 parent cd102d66
Exists in master

by Eriksen: Corrigido função de formatação para CEPs que comecem com 0

Showing 1 changed file with 16 additions and 11 deletions   Show diff stats
ieducar/intranet/include/funcoes.inc.php
... ... @@ -96,17 +96,22 @@
96 96 return substr( $str, 0, 2 ) . "." . substr( $str, 2, 3 ). "." . substr( $str, 5, 3 ) . "/" . substr( $str, 8, 4 ) . "-" . substr( $str, 12, 2 );
97 97 }
98 98  
99   - function int2CEP( $int )
100   - {
101   - if( $int )
102   - {
103   - return substr( $int, 0, 5 ) . "-" . substr( $int, 5, 3 );
104   - }
105   - else
106   - {
107   - return "";
108   - }
109   - }
  99 + /**
  100 + * Formata um valor numérico em uma representação string de CEP.
  101 + *
  102 + * @param string|int $int
  103 + * @return string
  104 + */
  105 + function int2CEP($int)
  106 + {
  107 + if ($int) {
  108 + $int = (string) str_pad($int, 8, '0', STR_PAD_LEFT);
  109 + return substr($int, 0, 5) . '-' . substr($int, 5, 3);
  110 + }
  111 + else {
  112 + return '';
  113 + }
  114 + }
110 115  
111 116 function limpa_acentos( $str_nome )
112 117 {
... ...