Different output results after STRRCHR

Source: Internet
Author: User
$str1 = "test:http://google.com,http://hbaidu.com";$str2 = strrchr($str1,"http://");echo $str2;

The output should be:

http://hbaidu.com

But why did the output result be:

baidu.com

If you remove the http://hbaidu.com h from the code,

$str1 = "test:http://google.com,http://baidu.com";$str2 = strrchr($str1,"http://");echo $str2;

The resulting output is:

http://baidu.com

May I ask you, the great God, why? Thank you

Reply content:

$str1 = "test:http://google.com,http://hbaidu.com";$str2 = strrchr($str1,"http://");echo $str2;

The output should be:

http://hbaidu.com

But why did the output result be:

baidu.com

If you remove the http://hbaidu.com h from the code,

$str1 = "test:http://google.com,http://baidu.com";$str2 = strrchr($str1,"http://");echo $str2;

The resulting output is:

http://baidu.com

May I ask you, the great God, why? Thank you

It is recommended to take a look at STRRCHR's documentation

http://php.net/manual/zh/function.strrchr.php

string strrchr ( string $haystack , mixed $needle )

The function returns a portion of the haystack string, starting at the last occurrence of needle, until the end of haystack.

Haystack
Look in the string.

Needle
If needle contains more than one character, only the first character is used. This behavior differs from STRSTR ().
If needle is not a string, it is converted to an integer and is treated as a character order value.

That is, the following parameters only recognize the first character, that is, only you h , and h then all parameters are ignored. If you want to use strings, you need to swap with other functions that support string queries such as Strpos.

(Note: The instructions upstairs are also inaccurate, this is not the same as trim, STRRCHR only recognizes the first character, the other characters are invalid, not a single attempt)

  • 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.