PHP str_word_count() string function

The str_word_count() function in PHP

The php str_word_count() sting function is used to count a number of words in a string.

str_word_count() function syntax


PHP str_word_count() function example

echo "The number of words in a string = ". str_word_count("Hello Meera Academy");

In above example there are three words in a given string the “Hello”, “Meera” and “Academy”.

The output is:

The number of words in a string = 3

PHP str_word_count() example with php form

<title>PHP str_word_count() Function</title>

<FORM method="POST" action="firstexample.php">

Name : <input type="text" name="name"></br></br>
<input type="submit" name="Submit1" value="Word count">


echo "The number of words in a string = ". str_word_count($_POST["name"]);


The out put is :

PHP str_word_count() string function
PHP str_word_count() string function

Leave a Reply

Your email address will not be published. Required fields are marked *