Home » PHP str_word_count() function

PHP str_word_count() function

by Online Tutorials Library

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 TutorAspire By using str_word_count(): 2  

Example 2

Output:

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

Example 3

Output:

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

Reference:

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

Next TopicPHP String

You may also like