stristr
(PHP 4, PHP 5, PHP 7, PHP 8)
Case-insensitive strstr
Description
Returns all of haystack starting from and including the first occurrence of needle to the end.
Parameters
haystackThe string to search in
needleThe string to search for.
Non-string
before_needleIf true,
stristr()returns the part of thehaystackbefore the first occurrence of theneedle(excluding needle).
needle and haystack are examined in a case-insensitive manner.
Return Values
Returns the matched substring. If needle is not found, returns false.
Changelog
| Version | Description |
|---|---|
| 8.0.0 | Passing an Integer as needle is no longer supported. |
| 7.3.0 | Passing an Integer as needle has been deprecated. |
Examples
stristr() example
<?php
$email = 'USER@EXAMPLE.com';
echo stristr($email, 'e'), PHP_EOL; // outputs ER@EXAMPLE.com
echo stristr($email, 'e', true), PHP_EOL; // outputs US
?>Testing if a string is found or not
<?php
$string = 'Hello World!';
if (stristr($string, 'earth') === FALSE) {
echo '"earth" not found in string';
}
// outputs: "earth" not found in string
?>