Skip to content

Instantly share code, notes, and snippets.

@wallacemaxters
Last active August 26, 2015 13:49
Show Gist options
  • Save wallacemaxters/e84468c98ba1dfb1e7c9 to your computer and use it in GitHub Desktop.
Save wallacemaxters/e84468c98ba1dfb1e7c9 to your computer and use it in GitHub Desktop.
<?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