stristr

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

haystack needle | string

<?

$haystack = 'CASEcase';
$needle = 's';

$return = stristr($haystack, $needle);

echo $return;

?>
SEcase

haystack needle | chr

<?

$haystack = 'CASEcase';
$needle = chr(115);

$return = stristr($haystack, $needle);

echo $return;

?>
SEcase

before_needle

<?

$haystack = 'CASEcase';
$needle = 's';
$before_needle = true;

$return = stristr($haystack, $needle, $before_needle);

echo $return;

?>
CA

Not Found

<?

$haystack = 'CASEcase';
$needle = 'not found';
$before_needle = true;

$return = stristr($haystack, $needle, $before_needle);

var_export($return);

?>
false

Internal

strstr

External

PHP

Home Menu