- preg_match: documentation ( source)
- str_split: documentation ( source)
- printf: documentation ( source)
<?php
$str = "12345678900";
function fr($cpf){
$regex = '#^\d{11}$#';
if(!preg_match($regex, $cpf)){
die("O campo CPF Inválido");
}
echo "CPF foi digitado corretamente </br>";
$arr = str_split($cpf, 3);
printf('%s.%s.%s-%s', ...$arr);
}
fr($str);