Free PHP Tutorials

home
Stay at Home and Learn

str_word_count( )

 
Computer Tutorials List

 

 

 

 

 

Tells you how many words a string has. The syntax is this:

str_word_count(string, return ,char)

If all you want to know is how many words a string has, then you can leave out "return", and "char". In which case, you can use it like this:

$num_of_words = str_word_count("The word count function");

print $num_of_words;

The return value can be one of three numbers:

0 - How many words found. This is the default
1 - Brings back the words found as an array.
2 - Brings back the words found as an array, but the Keys change based on where in the string the words are found. Might be useful to someone!

The char option is if you want the function to consider any additional words to count.