PHP string str_word_count() Function

The str_word_count() is in-built function of PHP. It is used to return information about words used in a string or counts the number of words in a string.

Syntax:

ParameterDescriptionRequired/Optional
stringSpecify the string to check.Required.
returnSpecify the return value of the function.
Values:
  • 0 : It is by default and returns number of words found
  • 1 - It returns an array with the words.
  • 2 - It returns value is the actual word.
Optional.
CharSpecify characters.Optional

Example 1

Output:

Your string is:PHP Javatpoint
By using str_word_count(): 2

Example 2

Output:

Your string is:PHP Javatpoint
Array ( 
[0] => PHP
 [1] => Javatpoint 
)

Example 3

Output:

Array ( [0] => Hello [1] => PHP [2] => Javatpoint ) Array ( [0] => Hello [1] => PHP [2] => & [3] => Javatpoint )

Reference:

http://php.net/manual/en/function.str-word-count.php
Next TopicPHP String




Latest Courses