Home > Backend Development > PHP Tutorial > PHP's four functions for finding strings in strings (strstr(), strchr(), strrchr(), stristr())

PHP's four functions for finding strings in strings (strstr(), strchr(), strrchr(), stristr())

黄舟
Release: 2023-03-16 21:00:02
Original
1676 people have browsed it

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 参数第一次出现之前的字符串部分。
Copy after login

Example:

echo strstr("I love Shanghai","love");//返回值为“love Shanghai”
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template