PHP strstr () strrchr () Strpos () Strrpos () function _php Tutorial

Source: Internet
Author: User
These four functions are character manipulation functions, mainly to determine the number of occurrences of characters, the need for friends can refer to.
The code is as follows Copy Code

STRSTR: Find return value from left to right: string
STRRCHR: Right-to-left lookup return value: string
Strpos: Find return value from left to right: integer, if the found string does not exist, returns an empty
Strrpos: Right-to-left lookup return value: integer
$STR = "High-flying birds, sea-wide diving";//strstr: Find strrchr from left to right
echo "Raw string:". $str. "
";
echo "Search with strstr function", "return Result:". Strstr ($str, ","). "
";
echo "uses the STRSTR function to search for" bird Fly "return results:". STRSTR ($str, "Bird Fly"). "
";

$str 1= "I have a great dream.";
echo "Raw string:". $str 1. "
";
echo "Searches for the return result of" E "with the STRRCHR function:". STRRCHR ($str 1, "E"). "
";
echo "Searches for the return result of the EA using the STRRCHR function:". STRRCHR ($str 1, "VE"). "
";

$str 2= "I am an abstract about abroad.";
echo "Original string is:" $str 2. "
";
The first occurrence of echo "AB in the string is:". Strpos ($str 2, "AB"). "
";
The first occurrence of echo "AB in the string is:". Strpos ($str 2, "AM"). "
";
The first occurrence of echo "ABCD in a string is:". Strpos ($str 2, "Aman"). "
";

$str 3= "I am is Wang Hui.";
echo "Original string is:" $str 3. "
";
The last occurrence of echo "I in the string is:". Strrpos ($str 3, "I"). "
";
The last occurrence of echo "an in the string is:". Strrpos ($str 3, "an"). "
";
The last occurrence of echo "I in the string is:". Strrpos ($str 3, "I");

?>

http://www.bkjia.com/PHPjc/631322.html www.bkjia.com true http://www.bkjia.com/PHPjc/631322.html techarticle These four functions are character manipulation functions, mainly to determine the number of occurrences of characters, the need for friends can refer to. Code to copy code like this? PHP//strstr: Left-to-right lookup 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.