English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String String Functions Manual
The stristr() function is used to search for the first occurrence of a string in another string.
string stristr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
It is used to search for the first match of a string in another string.
Note:This function is binary safe.
Note:This function is case-insensitive. To perform a case-sensitive search, please use strstr() Function.
Returns the matched substring. If needle is not found, returns FALSE.
Number | Parameters and Description |
---|---|
1 | haystack Required. Specify the string to be searched. |
2 | needle Required. Specify the string to be searched. If this parameter is a number, it will search for the character matching the ASCII value of the number. |
3 | before_needle Optional. If TRUE, strstr() will return the part before the needle in haystack (excluding needle). |
Try the following example to find the first occurrence of 'krishna' in 'sairam krishna' and return the remaining part of the string and the result passed after the third parameter:
<?php //return 'w'3all characters after the first occurrence of 'codebox'. echo stristr("www.oldtoolbag.com,"w3codebox); echo '<br>'; //return 'w'3all characters before the first occurrence of 'codebox' echo stristr("www.oldtoolbag.com,"w3codebox, true); ?>Test and see‹/›
Output Result
oldtoolbag.com www.