PHP stristr() function

The stristr() function is used to find the first occurrence of a string, return the part of string , stristr() function is case-insensitive of strstr()


stristr ( string $string , mixed $search_string, bool $before_search = FALSE) : string


Parameter Name Descrption
string Required, string
search_string Required, if search_string is number, it is converted to an integer search for mathing character with the ASCII value of number.
before_search Optional, DEFAULT is FALSE if set TRUE then return the part of string before the first occurrence of the $before_search

Return Value

Returns the string, if search_string is not found return FALSE

PHP stristr() examples

$string_web = '';
echo $new_string = stristr($string_web,'.');
//Output:: .com

echo $new_string = stristr($string_web,'.',TRUE);
//Output:: qoify

Related Functions

  • strstr(): Find the first occurrence of a string
  • strrchr(): Find the last occurrence of a character in a string
  • strpos(): Find the position of the first occurrence of a substring in a string
  • strpbrk(): Search a string for any of a set of characters