|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50317 strrpos offset behavior is opposite of what docs describe
Submitted: 2009-11-28 08:04 UTC Modified: 2009-12-19 11:01 UTC
From: codeslinger at compsalot dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2009-11-28 08:04 UTC] codeslinger at compsalot dot com
the actual behavior of the offset for strrpos is exactly the opposite of what the docs lead me to expect.

Reproduce code:
From manual page: function.strrpos#Description

Note:  As of PHP 5.0.0 offset  may be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string.  


but what actually happens is that 

Positive values define the stopping point 
Negative values define the starting point.

Expected result:
$foo = "0123456789a123456789b123456789c";

echo strrpos($foo, '7', -5);  //claim: stop searching after n chars (from the end of the string)

//Expected:  27  || Actual: 17

echo strrpos($foo, '7', 20);  //claim: start searching (backwards) n chars into the string.

//Expected:  17  || Actual: 27

echo strrpos($foo, '7', 28);

//Expected:  27  || Actual: false

Actual result:
as you can see from the examples, negative numbers define the point where it *starts* searching backwards offset from the end of the string.

and positive numbers define the point from the beginning of the string where it *stops* searching.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-19 11:01 UTC]
Automatic comment from SVN on behalf of degeberg
Log: Fixed #50317.
 [2009-12-19 11:01 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

 [2020-02-07 06:09 UTC]
Automatic comment on behalf of degeberg
Log: Fixed #50317.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Jan 29 20:05:54 2023 UTC