The output result is different after strrchr.

Source: Internet
Author: User
{Code ...} the output result should be: {code ...} but why is the output: {code ...} if you remove the h of hbaidu.com from the code {code ...} result output: {code ...} excuse me, why? Thank you.
$str1 = "test:http://google.com,http://hbaidu.com";$str2 = strrchr($str1,"http://");echo $str2;

The output result should be:

http://hbaidu.com

But why is the output:

baidu.com

If you remove the h of the http://hbaidu.com in the code

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

The result output is:

http://baidu.com

Excuse me, why? Thank you.

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

The output result should be:

http://hbaidu.com

But why is the output:

baidu.com

If you remove the h of the http://hbaidu.com in the code

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

The result output is:

http://baidu.com

Excuse me, why? Thank you.

We recommend that you first read the strrchr documentation.

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

string strrchr ( string $haystack , mixed $needle )

This function returns a part of the haystack string, starting with the last position of the needle until the end of the haystack.

Haystack
Search for the string.

Needle
If the needle contains more than one character, only the first character is used. This behavior is different from strstr ().
If needle is not a string, it is converted to an integer and considered as a sequential value.

That is to say, the following parameter only recognizes the first character, that is, only recognizes yourh,hAll subsequent parameters are ignored. To use strings, use strpos and other functions that support string query.

(Note: the upstairs description is not accurate. this is not the same as trim. strrchr only recognizes the first character. Other characters are invalid, rather than trying one by one)

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.