RE: [PHP] Split(), Explode()..
| From: | Maxim Maletsky | Date: | Thu, 19 Oct 2000 05:10:24 +0000 |
| Subject: | RE: [PHP] Split(), Explode().. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-21090@lists.php.net to get a copy of this message | ||
Thanks David,
I use both preg_split and the loop later.
at first I make a "real" array of characters in the string. (count() and
sizeof() do not send you anything)
then I use a for loop and match characters, doing not only whitespace
problem, but also other staff that I needed.
The whole problem I had was how to convert a string into an array of ALL
characters in it.
preg_split does exactly that.
Thank you all!
-----Original Message-----
From: David Robley [mailto:huntsman@hermes.nisu.flinders.edu.au]
Sent: Thursday, October 19, 2000 1:48 PM
To: Maxim Maletsky
Cc: 'PHP General List. (E-mail)'
Subject: RE: [PHP] Split(), Explode()..
On Thu, 19 Oct 2000, Maxim Maletsky wrote:
>
> So you're saying that a loop would be enough?
>
> but how?
>
> for() loop?
>
> can you pass me a simple sketch of what you mean , just to give me an
idea..
For - while - do while whatever kind of loop you like :-) Control it with
count($array) which tells the number of elements in an array.
Problem: take a string and separate each character with a space (untested);
$string = 'hello world';
for ($i = 0; $i < $count($string); $i++) {
$newstring[] = $string[$i] . ' ';
}
If you need, check that the character you are dealing with is not a space
before appending a space.
The preg_split solution is more elegant, but doesn't differentiate between
spaces and other characters.
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA