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

Share:
10,711
Michael Staudt
Author by

Michael Staudt

Updated on June 17, 2022

Comments