java lastIndexOf is specified,what is the similar method ini

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ismail
Forum Newbie
Posts: 10
Joined: Thu Jun 05, 2008 11:51 pm

java lastIndexOf is specified,what is the similar method ini

Post by ismail »

hi,
to find out last char we use lastIndexOf method in java, what is the similiar method in php
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Post 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);
}
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply