PHP count words

25.Aug.2010

In order to use PHP to count words in some text, you can use str_word_count – a PHP word count function. This is probably the simplest way to count words in your text.

PHP count words example:

1
2
3
4
5
//this line will output "3"
echo str_word_count("PHP count words");
 
//this line will output "9"
echo str_word_count("PHP str_word_count + is a word count function");