Re: String Question

From: Date: Thu, 01 Aug 2002 05:04:06 +0000
Subject: Re: String Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-110629@lists.php.net to get a copy of this message
Hi Randy, Just copy the following code and execute it, it works as you require, tested works fine. <? $string="abcdefghijklmnopqrstuvwxyz"; $length = strlen($string); // Finds the length of the string $octFull = round($length/8); // splits the length and finds how many // times 8 occurs in the length $intStart=0; //initilize the integer start to divided the string into 8's // Loop to divide the $string into 8 and print them. for($i =1;$i < $octFull+2;$i++) { //gets the substring of the string with the length of 8 $strDiv[$i] = substr($string,$intStart,8); //increment the start position to take the next 8 among the string $intStart = ($intStart+8); echo "<p>string$i : $strDiv[$i]</p>"; } ?> - JFK kishor Nilgiri Networks On Wed, 31 Jul 2002, Randy Johnson wrote: > Hello, > > I would like to be able to do the following but have not figured out a way to handle it > > $string="abcdefghijklmnopqrstuvwxz"; > > I would like to divde the above string into separate strings 8 charactes long , example > > $string1=abcdefgh > $string2=ijklmnop > $string3=qrstuvwx > $string4=yz > > if the string were only 10 long > > $string=abcdefghij > > then > > $string1=abcdefgh > $string2=ij > > any suggestions would be greatly appreciated. > > Thanks, > > > Randy >

« previous php.general (#110629) next »