On Thursday 08 March 2001 18:43, you wrote:
> I am attempting to take a line of text (a list) that has been entered
> into a form and split it into the appropriate parts, placing them into
> an array.  I am splitting the input on commas, semi-colons, and spaces.
>
> Problem 1:  Is with "white space".  If the input has spaces after a
> comma, it splits on the comma, but enters each "space" as a separate
> element of the array.
>
> Problem 2: Is with "white space" also.  If the input has just spaces
> between the appropriate parts, then it will split on the first "space",
> but enter the rest of the "spaces" as separate elements of the array.
>
> Here my code:
>       $course_list = preg_split("/[\,\;\s*]/", $input_list);

You can't put the asterisk in the character class - it's taken as literal 
asterisk in there.

try preg_split("/([\,\;]\s*)|(\s+)/", $input_list);

i.e. "either (',' or ';' eventually followed by spaces) or (at least one 
space)"

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

...10001000110101011010101101011110111010113...????

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