RE: [PHP] need help w/ Split()

From: Date: Thu, 08 Mar 2001 17:51:12 +0000
Subject: RE: [PHP] need help w/ Split()
Groups: php.general 
Request: Send a blank email to php-general+get-43043@lists.php.net to get a copy of this message
Your regex is incorrect. You've written: /[\,\;\s*]/ That * means "match a *" because it's inside the brackets. Put it outside, like this (actually use a + instead): /[\,\;\s]+/ to match 1 or more of any of those characters. That may not be exactly what you want, since that will also cause this: input "0101, 0102,,,,,0103" ==> [0101][0102][0103] If you want repeated commas to create empty elements, then try something like this: /\s*[\,\;\s]\s*/ I haven't tried that, but it looks right at first glance... Optional white space, followed by exactly one of ',; ', followed by optional white space. Nate -----Original Message----- From: Scott Walter [mailto:sdw1@geneseo.edu] Sent: Thursday, March 08, 2001 10:44 AM To: php-general@lists.php.net Subject: [PHP] need help w/ Split() 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); for ($i=0; $i<count($course_list); $i++) { echo("Item $i: $course_list[$i]<br>\n"); } Which on input "0101, 0102, 0103" produces [0101][ ][0102][ ][ ][ ][0103] Any help would be appreciated!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#43043) next »