php The stristr function is used to search for the first occurrence of a string in another string. Its syntax is stristr(string,search,before_search). The parameter string is required and specifies the string to be searched; search is required and specifies The string to search for.
#php How to use stristr function?
Definition and Usage
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.
Syntax
stristr(string,search,before_search)
Parameters
string Required. Specifies the string to be searched for.
search Required. Specifies the string to search for.
If the parameter is a number, search for characters matching the ASCII value corresponding to the number.
before_search Optional. The default value is a Boolean value of "false".
If set to "true", it will return the portion of the string before the first occurrence of the search parameter.
Return value: Returns the remaining part of the string (from the matching point). Returns FALSE if the searched string is not found.
PHP version: 4
Change log:
In PHP 5.3, the before_search parameter is added.
In PHP 4.3, this function becomes binary safe.
Example 1
Search for a string with the ASCII value of "o" and return the remainder of the string:
Output:
o world!
Example 2
Return the part of the string before the first occurrence of "world":
Output:
Hello
Example 3
Find the first occurrence of "world" in "Hello world!" and return the rest of the string:
Output:
world!
The above is the detailed content of How to use php stristr function?. For more information, please follow other related articles on the PHP Chinese website!