note 35387 added to function.strrpos
| From: | lee at rack1 dot php dot net | Date: | Fri, 29 Aug 2003 12:21:10 +0000 |
| Subject: | note 35387 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55291@lists.php.net to get a copy of this message | ||
I should have looked here first, but instead I wrote my own version of strrpos that supports
searching for entire strings, rather than individual characters. This is a recursive function. I
have not tested to see if it is more or less efficient than the others on the page. I hope this
helps someone!
//Find last occurance of needle in haystack
function str_rpos($haystack, $needle, $start = 0){
$tempPos = strpos($haystack, $needle, $start);
if($tempPos === false){
if($start == 0){
//Needle not in string at all
return false;
}else{
//No more occurances found
return $start - strlen($needle);
}
}else{
//Find the next occurance
return $this->str_rpos($haystack, $needle, $tempPos + strlen($needle));
}
}
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35387
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35387&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35387&report=yes