note 34021 added to function.strrpos
| From: | ara at bluemedia dot us | Date: | Mon, 14 Jul 2003 06:09:56 +0000 |
| Subject: | note 34021 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52060@lists.php.net to get a copy of this message | ||
derek@slashview.com notes a great replacement for strrpos because of the single character needle
limitation in the strrpos function. He made a slight error in the code. He adds the length of the
needle string instead of subtracting it from the final position. The function should be:
function strlastpos($haystack, $needle) {
# flip both strings around and search, then adjust position based on string lengths
return strlen($haystack) - strlen($needle) - strpos(strrev($haystack), strrev($needle));
}
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34021
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34021&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34021&report=yes