|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-07-25 11:45 UTC] 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): PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 07:00:01 2025 UTC |
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').