Re: More newbie problems -- this time regexp and split

From: Date: Tue, 05 Sep 2000 06:56:05 +0000
Subject: Re: More newbie problems -- this time regexp and split
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-15244@lists.php.net to get a copy of this message
On Mon, 4 Sep 2000, Rob Tanner wrote: > The browser returns a bunch of email addresses (one or more) entered > into a textarea block, separated by commas and/or whitespace. I try to > split it and I get the first element repeated by itself up to limit-1, > and the last element of the resulting array contains all the elements. > > To try and figure out what's wrong, I took a basic example from the > WROX PHP book: > > $str = "one two three four"; > $pat = " "; > $array = split($pat, $str, 4); > > print "$array[0]<BR>\n"; > print "$array[1]<BR>\n"; > print "$array[2]<BR>\n"; > print "$array[3]<BR>\n"; I don't know what to tell you. That code block works fine for me in 4.0.1 and 3.0.5, so.. :) One thing I may suggest (For a different direction) is that when you're separating a string based on a single character, explode() will always be faster. Adjusting the above example.. $str = 'one two three four'; $array = explode(' ',$str,4); will accomplish the same task without the PHP engine having to call upon a regexp to separate the string. Not an answer to your question, but it may help. Matt

« previous php.general (#15244) next »