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

mb_substr_count

Description

The mb_substr_count of Multibyte String for PHP 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