Page 1 of 1

java lastIndexOf is specified,what is the similar method ini

Posted: Mon Jul 21, 2008 5:16 am
by ismail
hi,
to find out last char we use lastIndexOf method in java, what is the similiar method in php

Re: java lastIndexOf is specified,what is the similar method ini

Posted: Mon Jul 21, 2008 5:57 am
by VladSun
There is no native one (as far as I know).
A copy-paste-code from http://bg2.php.net/strrpos :

Code: Select all

function rstrpos ($haystack, $needle, $offset)
{
    $size = strlen ($haystack);
    $pos = strpos (strrev($haystack), strrev($needle), $size - $offset);
  
    if ($pos === false)
        return false;
  
    return $size - $pos - strlen($needle);
}