Current Location: Home> Function Categories> mb_strrichr

mb_strrichr

Case insensitively looking for the last occurrence of a specified character in another string
Name:mb_strrichr
Category:Multi-byte string
Programming Language:php
One-line Description:Search for the specified character in the string and return to the last occurrence

Function name: mb_strrichr()

Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8

Usage: The mb_strrichr() function is used to search for the specified character in a string and return the last occurrence of the character. This function is an extension to the mb_strrchr() function and is case-insensitive.

Syntax: mb_strrichr(string $haystack, string $needle [, bool $part [, string $encoding = mb_internal_encoding()]]): string|false

parameter:

  • $haystack: The string to search for.
  • $needle: The character to search for.
  • $part (optional): If set to true, return all characters to the needle and its right. Default is false, only returning the last occurrence position of the needle and its characters to the right.
  • $encoding (optional): character encoding. If not specified, internal character encoding is used.

Return value:

  • If a needle is found, it returns the last occurrence position and the character to the right.
  • If no need is found, false is returned.

Example:

 $str = "Hello, World!"; $lastPos = mb_strrichr($str, "o"); echo $lastPos; // 输出"orld!" $lastPos = mb_strrichr($str, "O"); echo $lastPos; // 输出"orld!" $lastPos = mb_strrichr($str, "o", true); echo $lastPos; // 输出"o, World!" $lastPos = mb_strrichr($str, "O", true); echo $lastPos; // 输出"o, World!"

Notes:

  • This function requires support for the "mbstring" extension, and make sure that the extension is enabled in the PHP configuration file.
  • If the $encoding parameter is specified, the function will operate with the specified character encoding, otherwise the internal character encoding will be used.
  • This function is case-sensitive when searching for characters. If you need to be case-sensitive, use the mb_strrchr() function.
Similar Functions
Popular Articles