PHP stristr() Function

The stristr() function searches for the first occurrence of a string inside another string.

string stristr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] )

Returns all of haystack starting from and including the first occurrence of needle to the end.

Example -

Example #1 stristr() example

Example #2 Testing if a string is found or not

Example #3 Using a non "string" needle

ParameterDescription
haystackThe string to search in
needleIf needle is not a string, it is converted to an integer and applied as the ordinal value of a character.
before_needleIf TRUE, stristr() returns the part of the haystack before the first occurrence of the needle (excluding needle).

Returns the matched substring. If needle is not found, returns FALSE.