0
How to separate spaced words within a string?
I try using explode but I need more suggestions and please try in PHP
1 Antwort
+ 2
Explode should work, except that it will also include punctuation such as commas etc, that are adjacent to a word.
$str = "word1 word2 word3 word4";
$words = explode(" ", $str);
echo $words[0]; // outputs word1
If explode isn't working for you the way you want, you might give preg_split() a shot.
http://php.net/manual/en/function.preg-split.php