0

How to separate spaced words within a string?

I try using explode but I need more suggestions and please try in PHP

6th May 2018, 5:06 AM
vibha maniyar
vibha maniyar - avatar
1 Réponse
+ 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
6th May 2018, 5:23 AM
ChaoticDawg
ChaoticDawg - avatar