note 124027 added to function.strrpos
| From: | daveatpixelmetricsdotcom@php.net | Date: | Tue, 09 Jul 2019 22:22:30 +0000 |
| Subject: | note 124027 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211542@lists.php.net to get a copy of this message | ||
The description of offset is wrong. Hereâs how it works, with supporting examples.
Offset effects both the starting point and stopping point of the search. The direction is always
right to left. (The description wrongly says PHP searches left to right when offset is positive.)
Hereâs how it works:
When offset is positive, PHP searches right to left from the end of haystack to offset. This ignores
the left side of haystack.
When offset is negative, PHP searches right to left, starting offset bytes from the end, to the
start of haystack. This ignores the right side of haystack.
Example 1:
$foo = âaaaaaaaaaaâ;
var_dump(strrpos($foo, 'a', 5));
Result: int(10)
Example 2:
$foo = "aaaaaa67890";
var_dump(strrpos($foo, 'a', 5));
Result: int(5)
Conclusion: When offset is positive, PHP searches right to left from the end of haystack.
Example 3:
$foo = "aaaaa567890";
var_dump(strrpos($foo, 'a', 5));
Result: bool(false)
Conclusion: When offset is positive, PHP stops searching at offset.
Example 4:
$foo = âaaaaaaaaaaâ;
var_dump(strrpos($foo, 'a', -5));
Result: int(6)
Conclusion: When offset is negative, PHP searches right to left, starting offset bytes from the end.
Example 5:
$foo = "a234567890";
var_dump(strrpos($foo, 'a', -5));
Result: int(0)
Conclusion: When offset is negative, PHP searches right to left, all the way to the start of
haystack.
----
Server IP: 208.43.231.9
Probable Submitter: 119.81.81.244 (proxied: 71.218.37.158)
----
Manual Page -- http://php.net/manual/en/function.strrpos.php
Edit -- https://master.php.net/note/edit/124027
Del: integrated -- https://master.php.net/note/delete/124027/integrated
Del: useless -- https://master.php.net/note/delete/124027/useless
Del: bad code -- https://master.php.net/note/delete/124027/bad+code
Del: spam -- https://master.php.net/note/delete/124027/spam
Del: non-english -- https://master.php.net/note/delete/124027/non-english
Del: in docs -- https://master.php.net/note/delete/124027/in+docs
Del: other reasons-- https://master.php.net/note/delete/124027
Reject -- https://master.php.net/note/reject/124027
Search -- https://master.php.net/manage/user-notes.php