Home > Article > Backend Development > How to use php strstr function
The strstr() function is a built-in function in PHP. The syntax is strstr(string,search,before_search). It is used to search whether a string exists in another string. If so, return the string and the remaining part. , otherwise return FALSE. This function is case-sensitive.
php How to use strstr() function?
strstr() function searches whether a string exists in another string. If so, returns the string and the remaining parts, otherwise returns FALSE.
Note: This function is binary safe; this function is case-sensitive.
Syntax
strstr(string,search,before_search)
Parameters: The function accepts three parameters, as shown in the above syntax, of which the first two must be provided parameters, the third parameter is optional.
● 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 returns the portion of the string preceding the first occurrence of the search parameter.
Return value: This function returns the rest of the string (from the matching point), or FALSE if the string being searched is not found.
Let’s take a look at how to use the php strstr() function through an example.
Example 1:
<?php echo strstr("Hello world!","o"); ?>
Output:
o world!
Example 2:
<?php echo strstr("Hello world!","o", true); ?>
Output:
Hell
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!