Re: question about explode()

From: Date: Fri, 28 Sep 2001 07:12:59 +0000
Subject: Re: question about explode()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-69134@lists.php.net to get a copy of this message
Woops: so is there a syntactical way to tell explode to split at every **THIRD** character? is what i meant to say. not every character. crucial word omission.. On Fri, 28 Sep 2001, Rasmus Lerdorf wrote: > > $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. ha. sure enough. I dunno what time zone you're in, but it's late here and its starting to show. > > You might want to have a look at substr() looking .. yes, that seems like a solution, but as far as 'verbosity-of-code-per-simplicity-of-concept' it doesn't look to be much "cleaner" than the print ("($f[0]$f[1]$f[2]) $f[3]$f[4]$f[5]-$f[6]$f[7]$f[8]$f[9]"); option. Gradually I'm getting the impression that there's prolly just not a way to do $foo = explode ("...","1324567890",3); which makes me sad, cuz it seeme dlike such a sneaky use of the [int limit] option. sneaky when you're a php'er of my level, anyway. but thanks. --kevin

« previous php.general (#69134) next »