Find the first occurrence of "world" in "Hello world!" and return the rest of the string:
<?phpecho stristr("Hello world!","WORLD");?>The stristr() function searches for the first occurrence of a string within another string.
Note: This function is binary safe.
Note: This function is not case sensitive. For case-sensitive searches, use the strstr() function.
stristr( string,search,before_search )
parameter | describe |
---|---|
string | Required. Specifies the string to be searched for. |
search | Required. Specifies the string to search for. If the argument is a number, the search is for characters that match the ASCII value corresponding to the number. |
before_search | Optional. A Boolean value with a default value of "false". If set to "true", it will return the portion of the string preceding the first occurrence of the search parameter. |
Return value: | Returns the remainder of the string (from the matching point). Returns FALSE if the searched string is not found. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 5.3, the before_search parameter was added. In PHP 4.3, this function became binary safe. |
Searches a string by the ASCII value of "o" and returns the remainder of the string:
<?phpecho stristr("Hello world!",111);?>Return the portion of the string before the first occurrence of "world":
<?phpecho stristr("Hello world!","WORLD",true);?>