The PHP str_word_count() function


The str_word_count() function 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.

<-- Back One Page | Move on to the Next Part -->

Back to the PHP Contents Page