Explode string by one or more spaces or tabs
How can I explode a string by one or more spaces or tabs?
Example:
A B C D
I want to make this an array.
Solution 1:
$parts = preg_split('/\s+/', $str);
Solution 2:
To separate by tabs:
$comp = preg_split("/\t+/", $var);
To separate by spaces/tabs/newlines:
$comp = preg_split('/\s+/', $var);
To seperate by spaces alone:
$comp = preg_split('/ +/', $var);
Solution 3:
This works:
$string = 'A B C D';
$arr = preg_split('/\s+/', $string);
Solution 4:
The author asked for explode, to you can use explode like this
$resultArray = explode("\t", $inputString);
Note: you must used double quote, not single.