Phpstrstr () strrchr () strpos () strrpos () function _ PHP Tutorial

Source: Internet
Author: User
Phpstrstr () strrchr () strpos () strrpos () function. These four functions are character operation functions, mainly used to determine the number of occurrences of a character. For more information, see. The code is as follows: Copy the code? Phpstrstr: Returns from left to right. these four functions are character operation functions, mainly used to determine the number of occurrences of characters. if you need them, refer to them.
The code is as follows:

// Strstr: returns value from left to right: string
// Strrchr: returns a string from right to left.
// Strpos: return value from left to right: Integer. if the searched string does not exist, null is returned.
// Strrpos: return value from right to left: integer
$ Str = "sky high, birds fly, sea wide, fish jump"; // strstr: Search from left to right strrchr: Search from right to left
Echo "original string:". $ str ."
";
Echo "returns the result of searching", "using the strstr function:". strstr ($ str ,",")."
";
Echo "returns the result of searching" bird fly "using the strstr function:". strstr ($ str, "Bird fly ")."
";

$ Str1 = "I have a great dream .";
Echo "original string:". $ str1 ."
";
Echo "returns the result of searching" e "using the strrchr function:". strrchr ($ str1, "e ")."
";
Echo "use the strrchr function to search for the returned result of" ea ":". strrchr ($ str1, "ve ")."
";

$ Str2 = "I am an abstract about abroad .";
Echo "original string:". $ str2 ."
";
Echo "the first occurrence position of AB in the string is:". strpos ($ str2, "AB ")."
";
Echo "the first occurrence position of AB in the string is:". strpos ($ str2, "am ")."
";
Echo "the location where abcd first appears in the string is:". strpos ($ str2, "aman ")."
";

$ Str3 = "I am is wang hui .";
Echo "original string:". $ str3 ."
";
Echo "the last occurrence position of I in the string is:". strrpos ($ str3, "I ")."
";
Echo "the last appearance position of an in the string is:". strrpos ($ str3, "")."
";
Echo "the last occurrence of I in the string is:". strrpos ($ str3, "I ");

?>

Bytes. The code is as follows? Php // strstr: Search from left to right and return...

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.