Menu Samaritan's Purse

STR_WORD_COUNT

Return information about words used in a string

SYNTAX

str_word_count ( string $string [, int $format = 0 [, string $charlist ]] ) : mixed

PARAMETERS

string

The string

format

Specify the return value of this function.

0 returns the number of words found
1 returns an array containing all the words found inside the string
2 returns an associative array, where the key is the numeric position of the word inside the string and the value is the actual word itself
charlist

A list of additional characters which will be considered as 'word'

RETURN

Returns an array or an integer, depending on the format chosen.

EXAMPLES

STRING

7

FORMAT | 0

7

FORMAT | 1

Array
(
    [0] => Hello
    [1] => fri
    [2] => nd
    [3] => you're
    [4] => looking
    [5] => good
    [6] => today
)

FORMAT | 2

Array
(
    [0] => Hello
    [6] => fri
    [10] => nd
    [14] => you're
    [24] => looking
    [39] => good
    [44] => today
)

CHARLIST

Array
(
    [0] => Hello
    [6] => fri3nd
    [14] => you're
    [24] => looking
    [39] => good
    [44] => today!
)

PHP