The mb_stripos Function
The mb_stripos
function searches for the first occurrence of a substring in a string, case-insensitively.
Unlike stripos
, it works correctly with multibyte encodings (UTF-8 and others). It accepts the string to search as the first parameter, the substring to find as the second, the (optional) starting position as the third, and the encoding as the fourth.
Syntax
mb_stripos(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): int|false
Example
Find the position of a substring in a string:
<?php
$res = mb_stripos('AbCdE', 'bc');
echo $res;
?>
Code execution result:
1
Example
Search with a specified starting position:
<?php
$res = mb_stripos('AbCdE', 'cd', 2);
echo $res;
?>
Code execution result:
2
Example
Search with encoding specified:
<?php
$res = mb_stripos('Привет мир', 'МИР', 0, 'UTF-8');
echo $res;
?>
Code execution result:
7