PHP Using basename()


Example

basename(): Given a string containing the path to a file or directory, this function will return the trailing name component.

This function will return only the last part of an URL

$url = "http://example.com/project/controller/action/param1/param2";
$parts = basename($url);
// Output: param2

If your URL has more stuff to it and what you need is the dir name containing the file you can use it with dirname() like this:

$url = "http://example.com/project/controller/action/param1/param2/index.php";
$parts = basename(dirname($url));
// Output: param2