php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 + 40 = ?
Subscribe to this entry?

 
 [2009-11-28 08:04 UTC] codeslinger at compsalot dot com
Description:
------------
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 
and 
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-19 11:01 UTC] svn@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=292326
Log: Fixed #50317.
 [2009-12-19 11:01 UTC] degeberg@php.net
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] phpdocbot@php.net
Automatic comment on behalf of degeberg
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=6bb56ebdc39e4f54f73bdece1363b943a4f9e420
Log: Fixed #50317.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Mar 30 20:01:24 2020 UTC