note 26437 added to function.strrpos
| From: | DONT at rack1 dot php dot net | Date: | Wed, 30 Oct 2002 19:22:48 +0000 |
| Subject: | note 26437 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38764@lists.php.net to get a copy of this message | ||
that function can be modified to this
function strrpos_str ($string, $searchFor, $startFrom = 0)
{
$addLen = strlen ($searchFor);
$endPos = $startFrom - $addLen;
while (true)
{
if (($newPos = strpos ($string, $searchFor, $endPos + $addLen)) === false) break;
$endPos = $newPos;
}
return ($endPos >= 0) ? $endPos : false;
}
// example
$str = "abcabcabc";
$search = "ab";
$pos = strrpos_str ($str, $search);
if ($pos === false) echo "not found";
else echo $pos; // returns 6 in this case
--
http://www.php.net/manual/en/function.strrpos.php
http://master.php.net/manage/user-notes.php?action=edit+26437
http://master.php.net/manage/user-notes.php?action=delete+26437
http://master.php.net/manage/user-notes.php?action=reject+26437