Case-insensitive strstr()
Syntax
stristr(string $haystack, string $needle, bool $before_needle = false): string|false
Parameters
haystack
The string to search.
needle
The string to find.
The needle should either be explicitly cast to string, or an explicit call to chr() should be performed.
before_needle
If TRUE, stristr() returns the part of the haystack before the first occurrence of the needle (excluding needle).
Return
Returns the matched substring. If needle is not found, returns FALSE.
Examples
1 · haystack needle · string
<? $haystack = 'CASEcase'; $needle = 's'; $return = stristr($haystack, $needle); echo $return; ?>
SEcase
2 · haystack needle · chr
<? $haystack = 'CASEcase'; $needle = chr(115); $return = stristr($haystack, $needle); echo $return; ?>
SEcase
3 · before_needle
<? $haystack = 'CASEcase'; $needle = 's'; $before_needle = true; $return = stristr($haystack, $needle, $before_needle); echo $return; ?>
CA
4 · Not Found
<? $haystack = 'CASEcase'; $needle = 'not found'; $before_needle = true; $return = stristr($haystack, $needle, $before_needle); var_export($return); ?>
false