$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)