The mb_strpos Function
The mb_strpos function finds the position of the first occurrence of a substring in a string with support for multibyte encodings (e.g., UTF-8). The first parameter is the string to search in, the second is the substring to find, the third (optional) is the starting position for the search, and the fourth (optional) is the encoding.
Syntax
mb_strpos(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_strpos('abcde', 'b');
echo $res;
?>
Code execution result:
1
Example
Search with a specified starting position (starting from the 3rd character):
<?php
$res = mb_strpos('abcabc', 'a', 2);
echo $res;
?>
Code execution result:
3
Example
Search in a string with Cyrillic characters (UTF-8):
<?php
$res = mb_strpos('абвгде', 'в', 0, 'UTF-8');
echo $res;
?>
Code execution result:
2