PHP mb_strstr() Function Last Updated : 28 Mar, 2023 Comments Improve Suggest changes Like Article Like Report The mb_strstr() function is an inbuilt function in PHP that finds the first occurrence of a given string in the main string, i.e. it will search for the occurrence of the first needle in haystack, & id found then the portion of the haystack will be returned, otherwise return false. Syntax: mb_strstr( string $haystack, string $needle, bool $before_needle = false, ?string $encoding = null ): string|falseParameters: This function accepts four parameters that are described below: $haystack: This is the string where we search our substring. It is required must be a valid string$needle: This is the substring that you want to find in the $haystack string. It also must be a valid string.$before_needle: This is the optional parameter that determines whether to return haystack after or before $needle occurs. If this parameter is "true" it will return beginning to the first occurrence of the $needle string (excluding needle). If this parameter is set to "false", It will return from the beginning of the $needle to the $needle end.$encoding: This is the optional parameter that specifies the character encoding in the $haystack and $needle parameters. if the encoding is not provided it will use character encoding used.Return Values: This function returns the portion of $haystack, if the needle is found in a $haystack otherwise it will return "false". Example 1: The following program demonstrates mb_strstr() function. PHP <?php $string = "Hello, world!"; $sub = "world"; $pos = mb_strstr($string, $sub); echo $pos; ?> Output: world! Example 2: The following program demonstrates mb_strstr() function PHP <?php $string = "Geeks for Geeks"; $sub = "for"; $pos = mb_strstr($string, $sub, true); echo $pos; ?> Output: Geeks Reference: https://www.php.net/manual/en/function.mb-strstr.php Comment More infoAdvertise with us Next Article PHP mb_strstr() Function neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Multibyte-String Similar Reads PHP mb_stristr() Function The mb_stristr() is an inbuilt function in PHP that is used to get the first occurrence of a string within another string. It will check case insensitivity. Syntax:mb_stristr( $haystack, $needle, $before_needle, $encoding = null ): string|falseParameters: This function accepts 4 parameters that are 2 min read PHP strstr() Function The strstr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-sensitive. Syntax : strstr( $ 2 min read PHP mb_strpos() Function The mb_strpos() function is an inbuilt function in PHP that finds the position of string occurrence in the string. Syntax: mb_strpos( $haystack, $needle, $offset, $encoding ): int|falseParameters: This function accepts 4 parameters that are described below: $haystack: This parameter is the main stri 2 min read PHP stristr() Function The stristr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-insensitive. Syntax : strist 2 min read PHP strtr() Function The strtr() is an inbuilt function in PHP which is used to replace a substring in a string to a given string of characters. It also has the option to change a particular word to a different word in a string. The function is case sensitive. Syntax: strtr($string, $string1, $string2) or, strtr($string 4 min read PHP mb_stripos() Function The mb_stripos() function is an inbuilt case-insensitive function that finds the first occurrence of a substring in the string. Syntax: int|false mb_stripos( string $haystack, string $needle, int $offset , ?string $encoding);Parameters: This function accepts 4 parameters that are described below. $h 2 min read PHP mb_str_split() Function The mb_str_split() function was introduced in the release of PHP version 7.4.0 and it is only supported with PHP versions equal to or greater than 7.4.0. The mb_str_split() function serves as an alternate of str_split() function. It is used to split the given string with the specified length of chun 2 min read PHP mb_strtolower() Function The mb_strtolower() is a PHP inbuilt function that returns lowercase alphanumeric characters. Syntax: mb_strtolower(string $string, ?string $encoding = null): stringParameters: This function accepts 2 parameters: string: This parameter specifies the lowercase string.encoding: This parameter denotes 1 min read PHP mb_strtoupper() Function The mb_strtoupper() function is an inbuilt function in PHP that helps to transform the multibyte string to uppercase. Syntax: mb_strtoupper(string $string, ?string $encoding = null): string Parameters: This function has two parameters: string: This parameter specifies the string that is to be made t 1 min read PHP mb_strrichr() Function The mb_strrichr() function is a case-insensitive in-built function. This function searches a multi-byte string for the last occurrence of a specified character and returns the portion of the string. Syntax: mb_strrichr( $haystack, $needle, $before_needle , $encoding) : string|falseParameters:Â This f 2 min read Like