Created
November 9, 2013 11:01
-
-
Save caferrari/7384311 to your computer and use it in GitHub Desktop.
cpf.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cpfs = array( | |
'123.456.789-09', | |
'2.3.4.4.6.8.2.7.3.4.6', | |
'528.462.34.278', | |
'23131378912' | |
); | |
foreach ($cpfs as $cpf) { | |
echo preg_replace('@^(\d{3})(\d{3})(\d{3})(\d{2})$@', '$1.$2.$3-$4', preg_replace('@\D@', '', $cpf)) . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment