Menu Riverview Church

SUBSTR_COUNT

Count the number of substring occurrences

SYNTAX

substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] ) : int

PARAMETERS

haystack

The string to search in

needle

The substring to search for

offset

The offset where to start counting. If the offset is negative, counting starts from the end of the string.

length

The maximum length after the specified offset to search for the substring. It outputs a warning if the offset plus the length is greater than the haystack length. A negative length counts from the end of haystack.

RETURN

This function returns an integer.

EXAMPLES

HAYSTACK NEEDLE

3

OFFSET | NEGATIVE

2

OFFSET | NON-NEGATIVE

2

LENGTH | NEGATIVE

1

LENGTH | NON-NEGATIVE

1

PHP