note 42639 deleted from function.strrpos by betz
| From: | betz@php.net | Date: | Mon, 24 May 2004 21:47:11 +0000 |
| Subject: | note 42639 deleted from function.strrpos by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70043@lists.php.net to get a copy of this message | ||
Note Submitter: tsa@medicine.wisc.edu
----
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;
}
}