Several common character search functions in php

Source: Internet
Author: User
The code is as follows: Copy code

 

<? Php
// 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. "<br/> ";
Echo "returns the result of searching", "using the strstr function:". strstr ($ str, ","). "<br> ";
Echo "returns the result of searching" bird fly "using the strstr function:". strstr ($ str, "Bird fly"). "<br> ";

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

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

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

?>

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.