The str_word_count() function returns information about words used in a string.
Syntax
str_word_count(str, return, char)
Parameters
str − The string to check
return − The return value of the str_word_count() function.
The following are the possible values −
0 − It returns the number of words found
1 − It returns an array with the words from the string
2 − It returns an array where the key is the position of the word in the string, and value is the actual word.
char − The special characters to be considered as word.
Return
The str_word_count() function returns an array or number. It depends on the return parameter.
Example
The following is an example −
<?php print_r(str_word_count("Demo text!",1)); ?>
Output
Array ( [0] => Demo [1] => text )