tags:

views:

238

answers:

2

Is there any way to explode() using an array of delimiters?

PHP Manual:

array explode ( string $delimiter , string $string [, int $limit ] )

Instead of using string $delimiter is there any way to use array $delimiter without affecting performance too much?

+7  A: 

Use preg_split() with an appropriate regex.

Ignacio Vazquez-Abrams
For example: `print_r(preg_split("/[,. ]/", "0 1,2.3"));` will give you `Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3)`.
sirhc
`print_r(preg_split("/[,\. ]/", "0 1,2.3"));` you mean :)Thanks though, probably the best way I guess.
JoeC
+2  A: 

php's explode method doesn't support multiple delimiters, so you can't pass it an array. Also, what kind of string are you parsing that has multiple delimiters? you're best bet would be to loop through your delimiters, and re-explode some of the exploded strings.

GSto