Forum Moderators: coopster
Can any body tell how i can trape last occurance of a string in a string. I use strripos()function to do this. But it is available in php 5 ont in 4. And there is php4 installed on my web server. So my scriptting is not running properly. Can any body tell substitute of this function in php4.
Vineet.
The "find-last-occurrence-of-a-string" functions suggested here do not allow for a starting offset, so here's one, tried and tested, that does:function my_strrpos($haystack, $needle, $offset=0) {
// same as strrpos, except $needle can be a string
$strrpos = false;
if (is_string($haystack) && is_string($needle) && is_numeric($offset)) {
$strlen = strlen($haystack);
$strpos = strpos(strrev(substr($haystack, $offset)), strrev($needle));
if (is_numeric($strpos)) {
$strrpos = $strlen - $strpos - strlen($needle);
}
}
return $strrpos;
}
Hope this helps
Michal Cibor