In PHP, how can I split a string by whitespace, commas, and newlines at the same time
10,711
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']
.
Author by
Michael Staudt
Updated on June 17, 2022Comments
-
Michael Staudt almost 2 years
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?