Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function formataTelefone($numero){
- if(strlen($numero) == 10){
- $novo = substr_replace($numero, '(', 0, 0);
- $novo = substr_replace($novo, '9', 3, 0);
- $novo = substr_replace($novo, ')', 3, 0);
- }else{
- $novo = substr_replace($numero, '(', 0, 0);
- $novo = substr_replace($novo, ')', 3, 0);
- }
- return $novo;
- }
- $str = '1122223333';
- echo formataTelefone($str);
- (11)922223333
- static public function masc_tel($TEL) {
- $tam = strlen(preg_replace("/[^0-9]/", "", $TEL));
- if ($tam == 13) { // COM CÓDIGO DE ÁREA NACIONAL E DO PAIS e 9 dígitos
- return "+".substr($TEL,0,$tam-11)."(".substr($TEL,$tam-11,2).")".substr($TEL,$tam-9,5)."-".substr($TEL,-4);
- }
- if ($tam == 12) { // COM CÓDIGO DE ÁREA NACIONAL E DO PAIS
- return "+".substr($TEL,0,$tam-10)."(".substr($TEL,$tam-10,2).")".substr($TEL,$tam-8,4)."-".substr($TEL,-4);
- }
- if ($tam == 11) { // COM CÓDIGO DE ÁREA NACIONAL e 9 dígitos
- return "(".substr($TEL,0,2).")".substr($TEL,2,5)."-".substr($TEL,7,11);
- }
- if ($tam == 10) { // COM CÓDIGO DE ÁREA NACIONAL
- return "(".substr($TEL,0,2).")".substr($TEL,2,4)."-".substr($TEL,6,10);
- }
- if ($tam <= 9) { // SEM CÓDIGO DE ÁREA
- return substr($TEL,0,$tam-4)."-".substr($TEL,-4);
- }
- }
- echo self::masc_tel('5512123456789');
Add Comment
Please, Sign In to add comment