Skip to content

Instantly share code, notes, and snippets.

@cirpo
Created August 2, 2010 22:03
Show Gist options
  • Select an option

  • Save cirpo/505402 to your computer and use it in GitHub Desktop.

Select an option

Save cirpo/505402 to your computer and use it in GitHub Desktop.
<?php
$string = "1234567890";
$n = 3;
$numberOfCarachter = strlen($string);
echo "Number of Character: ".$numberOfCarachter."\n";
$newString = array();
$stringInitialPosition = 0;
while($stringInitialPosition < $numberOfCarachter){
echo "Initial Position: ".$stringInitialPosition."\n";
echo "Final Position: ".$stringFinalPosition."\n";
echo "---------------------------------\n";
$subString = substr($string, $stringInitialPosition, $n);
echo "Substring: ".$subString."\n";
$newString[] = $subString;
$stringInitialPosition += $n;
}
var_dump($newString);
$string = implode(' ', $newString);
echo $string."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment