strrchr with needle with multiple characters
| From: | Vincent Langlet | Date: | Mon, 02 Sep 2024 11:17:35 +0000 |
| Subject: | strrchr with needle with multiple characters | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-125382@lists.php.net to get a copy of this message | ||
I was today old when I discovered the big difference between strchr and
strrchr in the way they handle needle with multiple characters.
It's explained in the doc https://www.php.net/manual/en/function.strrchr.php
- If needle contains more than one character, only the first is used. This
behavior is different from that of strstr()
<https://www.php.net/manual/en/function.strstr.php>.
You can see an example https://3v4l.org/7j5ab
I feel like this behavior has no benefit (if I want to look for the first
character, I can pass
substr($needle, 0, 1) instead) and is just
error-prone.
Is there a reason for such behavior ? Would it be easy to change it (I have
no knowledge at all in C and in the existing PHP code) ?