views:

43

answers:

3

So, lets say I have a $somestring thats holds the value "main/physician/physician_view".

I want to grab just "physician_view". I want it to also work if the passed string was "main/physician_view" or "site/main/physician/physician_view".

Hopefully my question makes sense. Any help would be appreciated!

+1  A: 

You can use strrpos() to find the last occurence of one string in another:

substr($somestring, strrpos($somestring, '/') + 1)
Michael Mrozek
+1, fastest and most logical way.
Alix Axel
+2  A: 

Use basename, which was created for this exact purpose.

outis
+1, Humm... Nice, but also removes "\" (at least on Windows). Does what the OP wants but a little bit more than the title of the question asks.
Alix Axel
+2  A: 

There are many ways to do this. I would probably use:

array_pop(explode('/', $string));
Stephen
`explode` this: `str_repeat('/', 1337 * 1337);`
Alix Axel