How to find the number of words in a string in PHP?
How to find the number of words in a string in PHP?
PHP str_word_count() function is used.
The PHP str_word_count() function is used to find the number of words in a string.
For example:
<?php $my_str = 'The quick brown fox jumps over the lazy dog.'; // Outputs: 9 echo str_word_count($my_str); ?>