The stristr() function is used to search for the first occurrence of a string within another string, performing the search in a case-insensitive manner.
<span class="fun">stristr(str, search, before_search)</span>
str - The target string to search within.
search - The string to search for.
before_search - A boolean value, default is false. When set to true, the function returns the portion of the string before the first occurrence of the search string.
This function returns the portion of the string from the first match to the end, or if before_search is true, it returns the part before the matched string. If no match is found, it returns false.
The following code shows how to use the stristr() function:
<?php
$mystr = 'Tom Hanks!';
if (stristr($mystr, 'Tim') === FALSE) {
echo 'Tim is not in the string!';
}
?>
<span class="fun">Tim is not in the string!</span>
<?php
echo stristr("Demo text!", "TEXT", true);
?>
<span class="fun">Demo</span>
As shown in the examples above, the stristr() function is flexible and convenient, suitable for scenarios where case-insensitive string searching is required.