Re: question about explode()

From: Date: Fri, 28 Sep 2001 07:00:41 +0000
Subject: Re: question about explode()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-69132@lists.php.net to get a copy of this message
> $fone = "1234567890"; > > i have a db with fone number stored as numeric values just like that. > > I can use > explode (".", $fone); > to get an array with one digit per ... single unit of array. > > what i'd *like* to do (for the purpose of formatting) is do something > equivalent to > explode ("...", $fone, 3); > > to explode the string into 3 ... single units of array: > fone[0] containing 123 > fone[1] conatining 456 and the remaining 4 values (yay php4 and your limit > parameter) get stuck in the last: > fone[2] conaining 7890. > > then i can just print ("($fone[0]) fone[1]-fone[2]"); > > so is there a syntactical way to tell explode to split at every character? > explode ("."%3) or some wacky, freaky thing? You don't need to. Strings are already arrays. Did you try it? echo $fone[0].$fone[1].$fone[2]; > other such clean solutions would also be accepted. basically, what i > have now of: > > explode (".", $f); > print ("($f[0]$f[1]$f[2]) $f[3]$f[4]$f[5]-$f[6]$f[7]$f[8]$f[9]"); Your explode() doesn't do anything in the above. You might want to have a look at substr() -Rasmus

« previous php.general (#69132) next »