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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: myselfasunder at gmail dot com
New email:
PHP Version: OS:

 

 [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: Sat Dec 21 14:01:32 2024 UTC