Skip to content

Instantly share code, notes, and snippets.

@dharmastyle
Forked from cirpo/gist:505404
Created August 3, 2010 12:36
Show Gist options
  • Save dharmastyle/506301 to your computer and use it in GitHub Desktop.
Save dharmastyle/506301 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