Created
February 26, 2013 18:07
-
-
Save leoniralves/5040643 to your computer and use it in GitHub Desktop.
Função para acrescentar caracteres em sequências numéricas utilizando recursividade.
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 | |
function substring_format($value='', $local) | |
{ | |
$substring = substr_replace($value, '-'.(substr($value, strlen($value)-$local, 4)),strlen($value)-$local, 4); | |
if (substr($substring, 4, 1) != '-') { | |
return substring_format($substring, $local+5); | |
} | |
else { | |
return $substring; | |
} | |
return false; | |
} | |
$string = '35101158716523000119550010000000011003000000'; | |
$teste1 = (substring_format($string, 4)); | |
echo($teste1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment