The STRRCHR () function returns a result that is sometimes incorrect

Source: Internet
Author: User
STRRCHR () function returns the result sometimes wrong?
Classic examples in the manual:
Echo strrchr ("Hello world!", "World");
Output is: world!

But continuing to try will find these wonderful results:
Echo strrchr ("Hello aaaaworld!", "Aaaaworld");
Output: aworld!

Echo strrchr ("Hello cacworld!", "Cacworld");
Output: cworld!

Echo strrchr ("abc123cache123", "cache");
Output: che123

echo strrchr ("Cache", "cache");
Output: Che

And so on, in short, will return incomplete, always missing the first few characters, do not know why??
------Solution--------------------

A second parameter:
1. If more than one character is included, use only "first character"
2. If it is not a string, it will be converted to an integer and treated as a character order value
Example: Echo strrchr ("Hello aaaaworld!", "Aaaaworld");
Find string only with a, output: aworld!
This is right.


------Solution--------------------
PHP Manual:
If needle contains more than one character, only the first is used
If needle contains more than one character, only the first character is used. This behavior differs from STRSTR ().

W3school:
Specifies the character to find. If the parameter is a number, the character that matches the ASCII value of the number is searched.

Obviously the latter ignores the description "use only the first character"
But the characters to look for and the string to find are different.
  • 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.