Re: [PHP] Re: spliti[SOLUTION]

2001-12-22 Thread Philip Olson

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:

>  $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]




[PHP] Re: spliti[SOLUTION]

2001-12-22 Thread Bharath Bhushan Lohray



Tested and works



[PHP] Re: spliti

2001-12-22 Thread George Nicolae

$word=exlode(" ",$line);

--


Best regards,
George Nicolae
IT Manager
___
X-Playin - Professional Web Design
www.x-playin.f2s.com



"Yamin Prabudy" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> hi guys,
> I need help here.
> I got this
> $line = "no more words to say";
>
> then I want to split them all I used
>
> spliti(" ",$line);
>
> Then want to print it out say
> echo $word[0] $word[1] $word[$i];
>
> how can I do this..
>
> Thanks in Advance



-- 
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]