note 42638 added to function.strrpos
| From: | tsa at medicine dot wisc dot edu | Date: | Mon, 24 May 2004 21:18:23 +0000 |
| Subject: | note 42638 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70040@lists.php.net to get a copy of this message | ||
What the heck, I thought I'd throw another function in the mix. It's not pretty but the
following function counts backwards from your starting point and tells you the last occurrance of a
mixed char string:
function strrposmixed ($haystack, $needle, $start=0) {
// init start as the end of the str if not set
if($start == 0) {
$start = strlen($haystack);
}
// searches backward from $start
$currentStrPos=$start;
$lastFoundPos=false;
while($currentStrPos != 0) {
if(!(strpos($haystack,$needle,$currentStrPos) === false)) {
$lastFoundPos=strpos($haystack,$needle,$currentStrPos);
break;
}
$currentStrPos--;
}
if($lastFoundPos === false) {
return false;
} else {
return $lastFoundPos;
}
}
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42638
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42638&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42638&report=yes
Search -- http://master.php.net/manage/user-notes.php