Last active
August 26, 2015 13:49
-
-
Save wallacemaxters/e84468c98ba1dfb1e7c9 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Forçando números com 8 dígitos, separando os números por um hifen de 4 em 4 | |
**/ | |
$card_1 = 1234567; | |
$card_2 = 12345678; | |
$card_3 = 111222; | |
function number_separator($number, $amount = 1, $separator = '-', $forceSize = 0) | |
{ | |
$formatedNumber = sprintf("%0{$forceSize}s", $number); | |
return implode($separator, str_split($formatedNumber, $amount)); | |
} | |
number_separator($card_1, 4, '-', 4); // Imprime: '0123-4567' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment