Home >>PHP String Functions >PHP stristr() Function
PHP stristr() function is used to search for the first occurrence of a given input string inside another string and displays that portion of the latter starting from the first occurrence of the former in the latter.It is case-insensitive. The case-sensitive version of this function is strstr() function.
Syntax:
stristr( $string, $search, $before );
Parameter | Description |
---|---|
String | This is a required parameter. This parameter defines the string to search. |
Search | This is a required parameter. This parameter defines the string to search for. |
Before | This is an optional parameter. This parameter holds a boolean value which is by default "false". If it is "true", it returns the part of the string before the first occurrence of the search parameter. |
Here is an example of stristr() function in PHP:
<html> <body> <?php echo stristr("A B C D A B C D","c"); // case in-sensitive ?> </body> </html>
Here is an another example of stristr() function in PHP:
<html> <body> <?php echo stristr("A B C D E A B C D E.",67); ?> </body> </html>