Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 735
Michael Staudt Avatar asked Nov 05 '12 02:11

Michael Staudt


1 Answers

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'].

like image 118
deefour Avatar answered Sep 18 '22 20:09

deefour