Page 1 of 1

Remove the last directory from URL

Posted: Thu May 13, 2010 8:40 am
by klevis miho
Any ideas on how to removee the last folder from a given URL. For example:
www.example.com/test1/test2/test3

I want to remove only test3

Re: Remove the last directory from URL

Posted: Thu May 13, 2010 10:12 am
by timWebUK
Perhaps a regular expression? Read any valid characters then when you come across a '/' check for any further characters?

I'm no regex expert though, so you're on your own there!

Re: Remove the last directory from URL

Posted: Thu May 13, 2010 10:13 am
by klevis miho
Thnx man.
I found it out myself using strrpos().

Re: Remove the last directory from URL

Posted: Thu May 13, 2010 10:36 am
by pickle
basename() might be the simplest.