php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66563 strrchr ignores offset parameter
Submitted: 2014-01-23 22:32 UTC Modified: 2020-03-01 22:16 UTC
From: myselfasunder at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Strings related
PHP Version: 5.4.24 OS: OS X 10.9.1
Private report: No CVE-ID: None
 [2014-01-23 22:32 UTC] myselfasunder at gmail dot com
Description:
------------
The documentation indicates that the offset describes the number of characters from the front of the string, and that the search will -start- at the offset and move toward the beginning. 

However, the offset seems to be ignored.

Test script:
---------------
$buffer = '01234567890123456789';
var_dump(strrpos($buffer, '0', 5));


Expected result:
----------------
int(0)

Actual result:
--------------
int(10)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-23 23:19 UTC] requinix@php.net
-Type: Bug +Type: Documentation Problem
 [2014-01-23 23:19 UTC] requinix@php.net
The offset controls the start or end point for the search: positive offset is the ending point, negative offset is the starting point (from the end). So $offset=5 means to search from the end towards the beginning as usual but to stop at offset 5, and $offset=-5 means to search from offset ending-5 to the beginning.

According to that, the documentation should be changed to read like
 >offset
-> If specified, search will start this number of characters counted from the
+> If specified, search will end this number of characters counted from the
 > beginning of the string. If the value is negative, search will instead start
 > from that many characters from the end of the string, searching backwards.
 [2014-01-24 01:55 UTC] myselfasunder at gmail dot com
Confirmed. Thank you.
 [2020-03-01 22:16 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-03-01 22:16 UTC] cmb@php.net
Well, the respective documentation has been improved a while ago,
so I think this ticket can be closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 10 07:01:28 2024 UTC