#33852 [Fbk->Bgs]: Strrpos: offset param works from the end
| From: | vrana@php.net | Date: | Mon, 25 Jul 2005 13:13:19 +0000 |
| Subject: | #33852 [Fbk->Bgs]: Strrpos: offset param works from the end | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-82409@lists.php.net to get a copy of this message | ||
ID: 33852
Updated by: vrana@php.net
Reported By: sl at yes-co dot nl
-Status: Feedback
+Status: Bogus
Bug Type: Strings related
Operating System: Linux sarge 2.6.8
PHP Version: 5.1.0-dev
New Comment:
Quote whole parts and you will understand it: "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."
Thus strrpos('0123456789', '3', 5) is equal to strrpos('.....56789',
'3') and strrpos('0123456789', '3', -5) is equal to
strrpos('012345',
'3').
Previous Comments:
------------------------------------------------------------------------
[2005-07-25 12:34:27] tony2001@php.net
There are two fields int the report form: one for the result you expect
to get and second for the result you actually get.
Please fill them both.
------------------------------------------------------------------------
[2005-07-25 11:58:41] sl at yes-co dot nl
Offset also does not work from the end:
strrpos with offset
string: aaabaaaaaaaaaaaabaaa
strrpos($string, 'b', 1): 16
strrpos($string, 'b', 5): 16
strrpos($string, 'b', 15): 16
strrpos($string, 'b', 19):
strrpos($string, 'b', -5): 3
strrpos($string, 'b', -15): 3
This does not make sense.
------------------------------------------------------------------------
[2005-07-25 11:45:07] sl at yes-co dot nl
Description:
------------
The offset parameter of the strrpos function is the offset from the end
of the string. The documentation is unclear about this:
"As of PHP 5.0.0 offset may be specified to begin searching an
arbitrary number of characters into the string."
I would expect it to start at $string+$offset, searching backwards.
Reproduce code:
---------------
<?php
echo "strrpos with offset\n";
$string='abcdefghijklmnopqrstuvwxyz';
echo "string: $string\n";
echo 'strrpos($string, \'n\', 5): '.strrpos($string, 'n',
5)."\n";
echo 'strrpos($string, \'n\', 15): '.strrpos($string, 'n',
15)."\n";
echo 'strrpos($string, \'n\', -5): '.strrpos($string, 'n',
-5)."\n";
echo 'strrpos($string, \'n\', -15): '.strrpos($string, 'n',
-15)."\n";
?>
Actual result:
--------------
strrpos with offset
string: abcdefghijklmnopqrstuvwxyz
strrpos($string, 'n', 5): 13
strrpos($string, 'n', 15):
strrpos($string, 'n', -5): 13
strrpos($string, 'n', -15):
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33852&edit=1