In PHP, how can I split a string by whitespace, commas, and newlines at the same time

Michael Staudt picture Michael Staudt · Nov 5, 2012 · Viewed 9.6k times · Source

Possible Duplicate:
How to split a string by multiple delimiters in PHP?

What would be the most efficient way to split a string by three delimiters at the same time, specifically a single white space, newline, and commas?

Answer

deefour picture deefour · Nov 5, 2012

Since you've tagged your questions with php I will stick to that. See preg_split

$split_strings = preg_split('/[\ \n\,]+/', $your_string);

This will keep the array clean too, in case your string is something like some, ,,string, it will still result in ['some', 'string'] instead of ['some', '', '', '', 'string'].