Home > Article > Backend Development > How to use php strstr function
In PHP, the strstr() function is used to determine whether a string exists in another string. The syntax format is "strstr(string,search,before_search)"; if so, return the string and the remaining part, otherwise returns FALSE.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
strstr() function is a built-in function in PHP . This function searches for the presence of a string in another string; it searches for the first occurrence of that string in another string and displays the latter part. This function is case-sensitive.
Syntax
strstr(string,search,before_search)
Parameters | Description |
---|---|
string | Required. Specifies the string to be searched for. |
search | Required. Specifies the string to search for. If the argument is a number, searches for characters that match the ASCII value for that 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 remaining part of the string (from the matching point). Returns FALSE if the searched string is not found.
Example 1: Determine whether "world" exists in "Hello world!"
<?php echo strstr("Hello world!","world"); ?>
Output:
world!
Example 2: Search a string by the ASCII value of "o" and return the remaining part of the string
<?php echo strstr("Hello world!",111); ?>
Output:
o world!
Recommended learning:《 PHP video tutorial》
The above is the detailed content of How to use php strstr function. For more information, please follow other related articles on the PHP Chinese website!