RE: [PHP] question about explode()
| From: | Matthew Loff | Date: | Fri, 28 Sep 2001 07:27:06 +0000 |
| Subject: | RE: [PHP] question about explode() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-69137@lists.php.net to get a copy of this message | ||
No, but you can use a combination of a for() or while() loop and the
substr() function to accomplish that.
Look up substr() and I think you'll understand what I'm getting at...
-----Original Message-----
From: Kevin Keeler [mailto:insanity@uwns.underworld.net]
Sent: Friday, September 28, 2001 3:13 AM
To: Rasmus Lerdorf
Cc: php-general@lists.php.net
Subject: Re: [PHP] question about explode()
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net To
contact the list administrators, e-mail: php-list-admin@lists.php.net