Current Location: Home> Function Categories> mb_strripos

mb_strripos

Case insensitively find the last location of a string in a string
Name:mb_strripos
Category:Multi-byte string
Programming Language:php
One-line Description:Returns the last location of the specified string in another string (case insensitive)

Function name: mb_strripos()

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

Function Description: The mb_strripos() function returns the last occurrence of the specified string in another string (case insensitive). If the string is not found, false is returned.

Syntax: mb_strripos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|bool

parameter:

  • $haystack: The string to look for in it.
  • $needle: The string to be found.
  • $offset: Optional parameter, searching from the specified position of the string (default is 0).
  • $encoding: Optional parameter, specifying the character encoding to use (default is internal character encoding).

Return value:

  • If the specified string is found, the last occurrence position (in integer form) is returned.
  • If the specified string is not found, false is returned.

Example 1:

 $string = "Hello, World!"; $needle = "world"; $position = mb_strripos($string, $needle); if ($position !== false) { echo "找到了needle 在haystack 中的位置:$position"; } else { echo "未找到needle 在haystack 中"; }

Output:

找到了needle 在haystack 中的位置:7

Example 2:

 $string = "Hello, World!"; $needle = "WORLD"; $position = mb_strripos($string, $needle); if ($position !== false) { echo "找到了needle 在haystack 中的位置:$position"; } else { echo "未找到needle 在haystack 中"; }

Output:

找到了needle 在haystack 中的位置:7

Notes:

  • The mb_strripos() function is case-insensitive and can find case-insensitive matches.
  • If the $offset parameter is specified, the function starts the search from the specified location.
  • If the $encoding parameter is specified, the function will search with the specified character encoding.
Similar Functions
Popular Articles