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);
}
}
how to use:
echo self::masc_tel('5512123456789');
Come from the bank these values? It’s all together? There’s a similar question
– rray
Yes, they are stored in the bank all together, ex: 1122223333
– Thiago
Format in back-end or in a
<input>
front-end?– Guilherme Nascimento
Back-End, tagged php rs
– Thiago
In the example of this question he assumes that everyone starts with 9, but as I will take the value of the user, it may not be exactly that, you understand... I think with something with regex would be good.
– Thiago