I need to extract words from a string.
For example if the string is
$str = "It is a hot day";
I want to get the five words in this string as array
$word[0] = 'It';
$word[1] = 'is';
$word[2] = 'a';
$word[3] = 'hot';
$word[4] = 'day';
I have used the explode function to achieve my purpose like this
$str = "It is a hot day";
$word = explode(" ",str);
It works fine until the number of spaces between or after the words is one. But if the number of spaces or more than one between or after any word, it get that space as a word.
For example if the string is
$str = "It is a hot day";
Now, It has two spaces between 'is' and 'a'. So, when I convert it into array using explode function, it will give me six number of elements not five.
So, I want only words values in my array not any space as array value. How can I do that?