Home > Article > Backend Development > PHP's four functions for finding strings in strings (strstr(), strchr(), strrchr(), stristr())
To find another string in a string you can use strstr(),strchr(),strrchr(),stristr() Any one of the four functions.
The function strstr() is the most common. The function prototype is:
strstr(string,search,before_search); //string要被搜索的字符串,search所搜索的字符串,before_search默认值为 "false" 的布尔值,如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分。
Example:
echo strstr("I love Shanghai","love");//返回值为“love Shanghai”
The function strchr() is exactly the same as the function strstr();
The function stristr() is almost the same as the function strstr(). The difference between them is that the target keyword string of strstr() is case-sensitive, while the target keyword string of stristr() is not case-sensitive;
The function strrchr() is almost the same as the function strstr(), but strrchr() will return the searched string from before the last occurrence of the target keyword.
The above is the detailed content of PHP's four functions for finding strings in strings (strstr(), strchr(), strrchr(), stristr()). For more information, please follow other related articles on the PHP Chinese website!