Re: Re: spliti[SOLUTION]
| From: | Philip Olson | Date: | Sat, 22 Dec 2001 21:09:50 +0000 |
| Subject: | Re: Re: spliti[SOLUTION] | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-78593@lists.php.net to get a copy of this message | ||
I missed this thread but:
a) split takes on regex, explode does not.
b) spliti is case insensitive, spaces don't have cases.
So, in your example, might as well use explode.
$words = explode(' ', trim($string));
Although, let's say the following existed (it will):
$string = 'a b c d e f g ';
Then using regex might be appropriate, and trim() is always nice. Let's
split the above string by spaces and basically treat multiple spaces as
one:
$words = split('[ ]+', trim($string));
Otherwise many empty elements in $words will exist. This will also make
for a more reliable word count although it won't be perfect.
For examples on posix regex (which is taken on by split), see:
http://www.phpbuilder.com/columns/dario19990616.php3?print_mode=1
regards,
Philip Olson
On Sat, 22 Dec 2001, Bharath Bhushan Lohray wrote:
> <?php
> $line = "no more words to say";
> $word=spliti(" ",$line);
> echo "$word[0] $word[1] $word[3]";
> ?>
>
> Tested and works
>