$parts = preg_split('/\s+/', $str);
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);
This works:
$string = 'A B C D';
$arr = preg_split('/\s+/', $string);
The author asked for explode, to you can use explode like this
$resultArray = explode("\t", $inputString);
Note: you must used double quote, not single.
I think you want preg_split
:
$input = "A B C D";
$words = preg_split('/\s+/', $input);
var_dump($words);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With