← All docs

substr_count()

Counts the number of non-overlapping substring occurrences.

substr_count()

function substr_count(string $haystack, string $needle, int $offset = 0, mixed $length = null): int

Counts the number of non-overlapping substring occurrences.

Parameters:

  • $haystack (string)
  • $needle (string)
  • $offset (int), default 0, optional
  • $length (mixed), default null, optional

Returns: int

Availability

  • Compiled (AOT): supported by the Elephc code generator.
  • eval() (magician interpreter): not available inside eval’d code.

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

Internals

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