← All docs

str_word_count()

Counts the words in a string, or returns them as a list or byte-offset map.

str_word_count()

function str_word_count(string $string, int $format = 0, ?string $characters = null): array|int

Counts the words in a string, or returns them as a list or byte-offset map.

Parameters:

  • $string (string)
  • $format (int), default 0, optional
  • $characters (?string), default null, optional

Returns: array|int

Availability

No examples yet — check examples/ and showcases/ for usage patterns.

Internals

For how str_word_count is implemented in the compiler, see the internals page.