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
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to