From 1fbd73c13da23eb52b51f36e1a8aee8691e27ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Gusm=C3=A3o?= Date: Fri, 31 Aug 2018 09:53:32 -0300 Subject: [PATCH] normalize string --- src/Util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Util.php b/src/Util.php index 220f98da..6bf1c802 100644 --- a/src/Util.php +++ b/src/Util.php @@ -317,7 +317,7 @@ public static function normalizeChars($string) 'ß' => 'sz', 'þ' => 'thorn', 'º' => '', 'ª' => '', '°' => '', ); - return strtr($string, $normalizeChars); + return preg_replace('/[^0-9a-zA-Z !*\-$\(\)\[\]\{\},.;:\/\\#%&@+=]/', '', strtr($string, $normalizeChars)); } /** @@ -474,6 +474,7 @@ public static function numberFormatGeral($n, $loop, $insert = 0) public static function formatCnab($tipo, $valor, $tamanho, $dec = 0, $sFill = '') { $tipo = self::upper($tipo); + $valor = self::upper(self::normalizeChars($valor)); if (in_array($tipo, array('9', 9, 'N', '9L', 'NL'))) { if ($tipo == '9L' || $tipo == 'NL') { $valor = self::onlyNumbers($valor); @@ -486,7 +487,6 @@ public static function formatCnab($tipo, $valor, $tamanho, $dec = 0, $sFill = '' } elseif (in_array($tipo, array('A', 'X'))) { $left = '-'; $type = 's'; - $valor = self::upper(self::normalizeChars($valor)); } else { throw new \Exception('Tipo inválido'); }