php8.5
Home/ Manual/ mbstring / functions/ mb_substr_count

mb_substr_count

PHP function Edit on GitHub ✎

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

Count the number of substring occurrences

Description

mb_substr_count(string $haystack, string $needle, string|null $encoding = null): int

Counts the number of times the needle substring occurs in the haystack string.

Parameters

haystack

The string being checked.

needle

The string being found.

encoding

Parameter

Return Values

The number of times the needle substring occurs in the haystack string.

Changelog

VersionDescription

Examples

mb_substr_count() example

php
<?php
echo mb_substr_count("This is a test", "is"); // prints out 2
?>

See Also

Source: reference/mbstring/functions/mb-substr-count.xml · from the official PHP manual (php/doc-en)