Home > Article > Backend Development > stristr() function in PHP
stristr() function is used to search for the first occurrence of a string in another string.
Note - This function is not case sensitive
Syntaxstristr(str, search, before_search)
str - The string to search for
search - The string to search for
before_search - a boolean value, default value is "false". If set to "true", returns the portion of the string preceding the first occurrence of the search parameter.
The stristr() function returns the matching substring.
The following is an example-
Real-time demonstration
<?php $mystr = 'Tom Hanks!'; if(stristr($mystr, 'Tim') === FALSE) { echo 'Tim is not in the string!'; } ?>
Tim is not in the string!
The following is an example -
Live demonstration
<?php echo stristr("Demo text!","TEXT",true); ?>
Demo
The above is the detailed content of stristr() function in PHP. For more information, please follow other related articles on the PHP Chinese website!