PHP four functions to find strings in a string (Strstr (), STRCHR (), STRRCHR (), Stristr ())

Source: Internet
Author: User
Finding another string in a string can use either Strstr (), STRCHR (), STRRCHR (), STRISTR () four functions.

The function strstr () is the most common, and the function prototype is:

Strstr (String,search,before_search)//string the string to be searched, the string searched for by search, the Boolean value of the Before_search default value "false", and if set to "true", It returns the part of the string that precedes the first occurrence of the search parameter.

Cases:

Echo strstr ("I Love Shanghai", "Love");//return value is "Love Shanghai"

The function strchr () is exactly the same as the function strstr ().

function Stristr () is almost the same as the function strstr (), the difference between them is that the STRSTR () target keyword string is case-sensitive, and the target keyword string of stristr () is not case-sensitive;

The function strrchr () is also almost identical to the function strstr (), but STRRCHR () returns the searched string from before the position of the last occurrence of the target keyword.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.