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 N 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 Like