str_word_count Function in PHP
What is str_word_count Function?
Explanation
In PHP, this function is used to return information about words used in a string.
Syntax:
str_word_count(string,format,charlist)
In the above syntax given "string" is checked by the "format" specifying the format of the returned values.It can have the following values "0",returns the number of words found,"1", returns an array with words from the string,"2" returns array with the key as same as the position of the words."charlist" specifies the special characters to be considered as words.
Example :
<?php
print_r(str_word_count("Hi folks"));
print "<br>";
print_r(str_word_count("Hi folks",1));
print "<br>";
print_r(str_word_count("Hi folks",2));
?>
Result :
2
Array
(
[0] = Hi
[1] = folks
)
Array
(
[0] = Hi
[3] = folks
)
In the above example "Hi folks" is displayed using the split into a array of individual string using different formatting options.