need the last part of the url
http://example.com then the last part is nothing if it is http://example.com/i then last part is i if it is http://example.com/i/am/fil
For those of you using a CMS like WordPress or Magento that add a trailing slash, there is an easy addition to Vasil's solution:
You can even just use a simple Request URI call like this:
$request_path = $_SERVER['REQUEST_URI'];
$path = explode("/", $request_path); // splitting the path
$last = end($path);
$last = prev($path);