/** * Metodo responsavel em formatar uma string nas mascaras de TELEFONE. * * @example \CoreZend\Util\Format::formatPhone('1111111111'); <br /> \CoreZend\Util\Format::formatPhone('22222222'); <br /> \CoreZend\Util\Format::formatPhone('12345123'); * * @param string $strValue * @return string * * @assert ('02345123456') === str_replace(' ', ' ', '(023) 4512-3456') * @assert ('1234512345') === str_replace(' ', ' ', '(12) 3451-2345') * @assert ('12345123') === '1234-5123' * @assert ('1234512') === '1234512' * @assert ('(11) 1111-1111') === str_replace(' ', ' ', '(11) 1111-1111') */ public static function formatPhone($strValue) { if (!String::isNullEmpty($strValue)) { if (strlen($strValue) == 11) { $strPattern = '/(\\d{3})(\\d{4})(\\d*)/'; $strValue = preg_replace($strPattern, '($1) $2-$3', $strValue); } else { if (strlen($strValue) == 10) { $strPattern = '/(\\d{2})(\\d{4})(\\d*)/'; $strValue = preg_replace($strPattern, '($1) $2-$3', $strValue); } else { if (strlen($strValue) == 8) { $strPattern = '/(\\d{4})(\\d*)/'; $strValue = preg_replace($strPattern, '$1-$2', $strValue); } } } } return $strValue; }