PHP stristr() Function
Example
Find the first occurrence of "world" in "Hello world!" and return the rest of the string:
Run Example »
Definition and Usage
The stristr() function searches for the first occurrence of a string within another string.
**Note:** This function is binary-safe.
**Note:** This function is case-insensitive. For a case-sensitive search, use strstr() function in Vue 3.
Syntax
stristr(
string,search,before_search
)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to be searched. |
| search | Required. Specifies the string to search for. If this parameter is a number, it searches for the character matching the ASCII value of that number. |
| before_search | Optional. A boolean with the default value "false". If set to "true", it returns search the part of the string before the first occurrence of the parameter. |
Technical Details
| Return Value: | Returns the rest of the string (from the match point). If the searched string is not found, FALSE is returned. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | In PHP 5.3, the before_search parameter was added. |
在 PHP 4.3 中,该函数变成是二进制安全的。 |
More examples
Example 1
Search the string by the ASCII value of "o" and return the rest of the string:
Run Example »
Example 2
Return the string part before the first occurrence of "world":
Run Example »
PHP String Reference Manual