The mb_stristr Function
The mb_stristr function searches for the first occurrence of a substring in a string case-insensitively and returns the part of the string from the beginning of the found occurrence to the end. The first parameter is the string to search in, the second is the substring to find, the third (optional) is a boolean value to return the part of the string before the occurrence, and the fourth (optional) is the encoding.
Syntax
mb_stristr(string $haystack, string $needle, bool $before_needle = false, ?string $encoding = null): string|false
Example
Let's find a substring in a string case-insensitively:
<?php
$res = mb_stristr('ABCDE', 'bc');
echo $res;
?>
Code execution result:
'BCDE'
Example
Using the $before_needle parameter to get the part of the string before the occurrence:
<?php
$res = mb_stristr('ABCDE', 'bc', true);
echo $res;
?>
Code execution result:
'A'
Example
Search with UTF-8 encoding specified:
<?php
$res = mb_stristr('Привет мир', 'МИР', false, 'UTF-8');
echo $res;
?>
Code execution result:
'мир'