Javatpoint Logo
Javatpoint Logo

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:

Parameter Description Required/Optional
string Specify the string to check. Required.
return Specify 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.
Char Specify 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




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials