The mb_stripos Function

The mb_stripos function finds the first occurrence of a substring in a string, ignoring character case. Unlike stripos, it works correctly with multibyte encodings (UTF-8 and others). Its 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 is the encoding.

Syntax

phpmb_stripos(string $haystack, string $needle, int $offset = 0, ?string $encoding = null): int|false

Example

Find the position of a substring in a string:

php<?php
  $res = mb_stripos('AbCdE', 'bc');
  echo $res;
?>

Code execution result:

php1

Example

Search with a specified starting position:

php<?php
  $res = mb_stripos('AbCdE', 'cd', 2);
  echo $res;
?>

Code execution result:

php2

Example

Search with encoding specified:

php<?php
  $res = mb_stripos('Привет мир', 'МИР', 0, 'UTF-8');
  echo $res;
?>

Code execution result:

php7

See Also

  • the mb_strpos function,
    which performs a case-sensitive search
  • the stripos function,
    which works similarly but without multibyte encoding support