Name

str_word_count

Synopsis

mixed str_word_count(stringstring[, int format[, string characters]])

Counts the number of words in string using locale-specific rules. The value of format dictates the returned value:

0 (default)

The number of words found in string

1

An array of all words found in string

2

An associative array, with keys being the positions and values being the words found at those positions in string

If characters is specified, it provides additional characters that are considered to be inside words (that is, are not word boundaries).

Get Programming PHP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.