I have a text string in the following format
$str= "word1 word2 word3 word4 ";
So I want to separate each word from the string. Two words are separated by a blank space
How do I do that? Is there any built-in function to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The easiest would be to use
explode:But that does only accept fixed separators.
splitanpreg_splitdo accept regular expressions so that your words can be separated by multiple spaces:Now you can additionally remove leading and trailing spaces with
trim: