You are currently viewing How to Count PHP Words
  • Post category:PHP

How to Count PHP Words

How to count php words

In this article, we will see how to count php words. We can use PHP str_word_count() in-built function to count the number of words in a string. We should pass a parameter string or string containing variables. This is a very easy way to find string words.

Ex:

<?php
$str = "My name is James Bond";
echo str_word_count($str); // count words and output is 5
?>

Here, we have created a variable “$str” and it has some string value.
I want to find the word count, so I used the “str_word_count()” function and pass the variable $str as a value.
The variable $str has 5 words, so it returns 5.

Leave a Reply