Hello Friends Today, through this tutorial, I will tell you How do You find the number of words in a string in PHP With Example? You can find the number of words in a string in PHP by using the `str_word_count()` function. Here’s an example:
<?php $string = "The quick brown fox jumps over the lazy dog"; $wordCount = str_word_count($string); echo "Number of words in the string: $wordCount"; ?>
Output:
Number of words in the string: 9
In this example, the `$string` variable contains a sentence. We use the `str_word_count()` function to count the number of words in the string, and then we output the result. The function returns the number of words found in the string.