✏️ 正在编辑: Refatorar.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/library/String/Refatorar.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class String_Refatorar { public static function formatarCpf($cpf, $digito = null) { $cpf = preg_replace("/[^0-9]/", "", $cpf); if(!empty($digito)){ $cpf .= preg_replace("/[^0-9]/", "", $digito); } return str_pad(trim($cpf), 11, '0', STR_PAD_LEFT); } public static function formatarCnpj($value) { $cnpj = preg_replace("/[^0-9]/", "", $value); return str_pad(trim($cnpj), 14, '0', STR_PAD_LEFT); } public static function formatarTelefone($telefone, $ddd = null) { $telefone = preg_replace("/[^0-9]/", "", $telefone); if(!empty($ddd)){ $telefone = preg_replace("/[^0-9]/", "", $ddd) . $telefone; } return trim(ltrim($telefone,'0')); } public static function removerAcentuacao($value) { $value = preg_replace(array( "/(á|à|ã|â|ä)/", "/(Á|À|Ã|Â|Ä)/", "/(é|è|ê|ë)/", "/(É|È|Ê|Ë)/", "/(í|ì|î|ï)/", "/(Í|Ì|Î|Ï)/", "/(ó|ò|õ|ô|ö)/", "/(Ó|Ò|Õ|Ô|Ö)/", "/(ú|ù|û|ü)/", "/(Ú|Ù|Û|Ü)/", "/(ñ)/", "/(Ñ)/", "/(Ç)/", "/(ç)/" ), explode(" ", "a A e E i I o O u U n N C c"), $value); return $value; } public static function resetCnpj($value) { $value = preg_replace("/[^0-9]/", "", $value); if( strlen($value) == 14 ) return preg_replace("/([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{4})([0-9]{2})/", "$1.$2.$3/$4-$5", $value); else return $value; } public static function resetCpf($value) { $value = preg_replace("/[^0-9]/", "", $value); if( strlen($value) == 11 ) return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{2})/", "$1.$2.$3-$4", $value); else return $value; } public static function resetTelefone($value, $dddZero = false) { $value = preg_replace("/[^0-9]/", "", $value); if (strlen($value) == 11) { if ($dddZero) { $value = "0" . $value; return preg_replace("/([0-9]{3})([0-9]{5})([0-9]{4})/", "($1) $2-$3", $value); } return preg_replace("/([0-9]{2})([0-9]{5})([0-9]{4})/", "($1) $2-$3", $value); } return $value; } /** * Converte o número para a letra correspondente do alfabeto * @param int $number * @return string */ public static function converterNumberToAlpha($number) { if( $number > 0 ){ $alfabeto = array(); for ( $i = 65; $i < 91; $i++ ) { $alfabeto[] = chr($i); } return $alfabeto[$number]; } return null; } /** * Retorna apenas os números de uma string passada por parâmetro * @param string $string * @return string */ public static function soNumeros($string) { return preg_replace("/[^0-9]/", "", $string); } function bytesConverter($bytes) { if( $bytes >= 1073741824 ){ $bytes = number_format($bytes / 1073741824, 2) . ' GB'; } elseif( $bytes >= 1048576 ){ $bytes = number_format($bytes / 1048576, 2) . ' MB'; } elseif( $bytes >= 1024 ){ $bytes = number_format($bytes / 1024, 2) . ' KB'; } elseif( $bytes > 1 ){ $bytes = $bytes . ' bytes'; } elseif( $bytes == 1 ){ $bytes = $bytes . ' byte'; } else { $bytes = '0 bytes'; } return $bytes; } public static function ordenarExtrato($a, $b) { $retval = strnatcmp($a['data_pagamento'], $b['data_pagamento']); if( !$retval ) return strnatcmp($a['data_pagamento'], $b['data_pagamento']); return $retval; } public static function calcularIdade($idade) { $now = Zend_Date::now(); $ano = $now->subDate($idade, Zend_Date::YEAR)->get('yyyy'); return $now->isDate($ano, 'yyyy') ? $ano : false; } public static function resetNumero($value, $digits = 8) { while ( strlen($value) < $digits ) { $value = '0' . $value; } return $value; } public static function soLetra($str) { return preg_replace("/[^A-Za-z]/", "", $str); } /** * Recebe um valor numérico (int, float, string) formatado de diversas * localidades e retorna um float * @param string $value valor a ser convertido para float * @return float */ public static function parseStringToFloat($value) { if( empty($value) ){ return 0.00; } $string = (string) $value; $dotPos = strrpos($string, '.'); $commaPos = strrpos($string, ','); $sep = (($dotPos > $commaPos) && $dotPos) ? $dotPos : ((($commaPos > $dotPos) && $commaPos) ? $commaPos : false); if(empty($dotPos) && empty($commaPos) && !empty($string)){ return (float)@number_format($string, 2, '.', ''); } if (!$sep) { return floatval(preg_replace("/[^\d-]+/", "", $string)); } return floatval( preg_replace("/[^\d-]+/", "", substr($string, 0, $sep)) . '.' . preg_replace("/[^\d-]+/", "", substr($string, $sep+1, strlen($string))) ); } public static function ocultarCaracteres(string $string, int $qtdOcultar = 5) : string { $stringOcultada = substr($string, 0, strlen($string)-$qtdOcultar); return str_pad(trim($stringOcultada), strlen($string), '*', STR_PAD_RIGHT); } public static function removeAspas(?string $string) : string { return str_replace("'", "", str_replace("\"", "", $string)); } }
💾 保存文件
← 返回文件管理器