Give this a whirl:


$string = "abcdefghijklmnopqrstuvwxyz";
$len = strlen($string)  // in this case, 26

for($i=0; $i < $len; $i+8) {
   $str_array[] = substr($string, $i, 8);

for($i=0; $i < count($str_array); $i++) {
   echo $str_array[$i] . "<br>\n";


I haven't tested it, but in theory it should find the length of the string (26), loop 
through it as long as $i is less than 26, incrementing 8 at a time.  Each time it goes 
through, $str_array[] is fed a new element, which is a substring of $string that 
starts at $i (0, 8, 16, 24, etc) and grabs 8 characters.  So here is how the data 
should be retrieved.

1st loop:  0-7 (8 elements)
2nd loop:  8-15 (8 elements)
3rd loop:  16-23 (8 elements)
4th loop:  24-26 (3 elements)

Let me know how it works out for you :o)

Martin Clifford
Developer's Forums:

>>> "Randy Johnson" <[EMAIL PROTECTED]> 07/31/02 03:26PM >>>

I would like to be able to do the following but have not figured out a way to handle it


I would like to divde the above string into separate strings 8 charactes long , example


if the string were only 10 long




any suggestions would be greatly appreciated.



PHP General Mailing List (
To unsubscribe, visit:

Reply via email to