Skip to content

Instantly share code, notes, and snippets.

@leoniralves
Created February 26, 2013 18:07
Show Gist options
  • Save leoniralves/5040643 to your computer and use it in GitHub Desktop.
Save leoniralves/5040643 to your computer and use it in GitHub Desktop.
Função para acrescentar caracteres em sequências numéricas utilizando recursividade.
<?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