PHP strstr() function

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


strstr ( 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 strstr() examples

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

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

Related Functions

  • stristr(): Case-insensitive strstr
  • 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