Split a PHP string that has multiple spaces
This will split a string that has multiple spaces inside:
$str = " lazy fox did whatever ";
$array_result = preg_split("/[\s]+/", trim($str));
The resulting array contains the following tokens: lazy, fox, did, whatever. But you got to use the trim() function first, otherwise the array will contain an empty element at the end.
First I tried to use the explode() function, but it created array elements containing spaces. Preg_split() did the trick.
