Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

mb_substr_count

Description

Count the number of substring occurrences

Syntax

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

Parameters

haystack

The string being checked.

needle

The string being found.

encoding

The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used.

Return

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

Examples

1 · haystack needle

<?

$haystack = '🐘🐘🐘';
$needle = '🐘';

$return = mb_substr_count($haystack, $needle);

echo $return;

?>
3

2 · encoding

<?

$haystack = '🐘🐘🐘';
$needle = '🐘';
$encoding = 'UTF-8';

$return = mb_substr_count($haystack, $needle, $encoding);

echo $return;

?>
3
HomeMenu