Current Location: Home> Function Categories> mb_stristr

mb_stristr

Case insensitively search for the first occurrence of a string in another string
Name:mb_stristr
Category:Multi-byte string
Programming Language:php
One-line Description:Find the specified substring in a string and return the part from the specified substring to the end of the string

Function name: mb_stristr()

Applicable version: PHP 4.0.6 and above

Usage: The mb_strstr() function is used to find a specified substring in a string and returns the part from the specified substring to the end of the string. This function is a multibyte character-safe version of the strristr() function.

Syntax: mb_strstr(string $haystack, string $needle, bool $before_needle = false, string $encoding = mb_internal_encoding()): string|false

parameter:

  • $haystack: The string to search for.
  • $needle: The substring to search for.
  • $before_needle (optional): If set to true, return the part before the specified substring; if set to false (default), return the part after the specified substring.
  • $encoding (optional): Specifies the character encoding of the string. If this parameter is not provided, the internal encoding returned by the mb_internal_encoding() function is used by default.

Return value:

  • If the specified substring is found, the portion from that substring to the end of the string is returned.
  • If the specified substring is not found, false is returned.

Example:

 $str = "Hello, World!"; $substring = "WORLD"; $result = mb_stristr($str, $substring); echo $result; // 输出:World! $result = mb_stristr($str, $substring, true); echo $result; // 输出:Hello, $result = mb_stristr($str, "abc"); var_dump($result); // 输出:bool(false)

In the example above, we use the mb_strstring() function to search for $substring in the string $str . In the first example, the function returns the part from the substring World to the end of the string, i.e. World! . In the second example, we set the third parameter to true, and the function returns the part before the substring World , i.e. Hello, . In the last example, we searched for a substring abc that does not exist and the function returns false.

Similar Functions