string_word_count() Function

  • PHP str_word_count() function counts the number of words in String.
  • The given example shows the use of PHP str_word_count() function:
<!DOCTYPE html>

<html>

<body>

<?php

echo str_word_count("www.eitworld.com");

echo "<br>";

echo str_word_count("Popular Tutorial");

echo "<br>";

echo str_word_count("PHP Tutorial");

?>

</body>

</html>

Output

string
    In the above example:
  • There are three words in first string www.eitworld.com that's why str_word_count() function returns 3.
  • There are two words in Second string Popular Tutorial that's why str_word_count() function returns 3.
  • There are two words in Third string PHP Tutorial that's why str_word_count() function returns 3.