Current Location: Home> Function Categories> mb_stripos

mb_stripos

Case insensitively find where a string first appears in another string
Name:mb_stripos
Category:Multi-byte string
Programming Language:php
One-line Description:Find another string in one string (case insensitive)

Function name: mb_stripos()

Applicable version: PHP 4 >= 4.2.0, PHP 5, PHP 7

Function Description: The mb_stripos() function looks for another string (case insensitive). Similar to the stripos() function, but mb_stripos() supports multibyte characters.

Syntax: mb_stripos(string $haystack, string $needle, int $offset = 0, string $encoding = mb_internal_encoding()): int|false

parameter:

  • $haystack: A string in which to look for a substring.
  • $needle: The substring to be found.
  • $offset (optional): Starts searching from the specified location of the string.
  • $encoding (optional): Specify character encoding, default to internal character encoding.

Return value:

  • If a substring is found, it returns its position in the string (index starting at 0).
  • If no substring is found, false is returned.

Example:

 $haystack = "Hello, World!"; $needle = "world"; $position = mb_stripos($haystack, $needle); if ($position !== false) { echo "找到子字符串,位置为:" . $position; } else { echo "未找到子字符串"; }

Output:

找到子字符串,位置为:7

Notes:

  • The mb_stripos() function is case-insensitive. If you need a case-sensitive search, please use the mb_stripos() function.
  • If the specified string encoding is invalid, a warning will be thrown.
Similar Functions
Popular Articles