Skip to content

Instantly share code, notes, and snippets.

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