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
$url = 'http://example.com/i/am/file.php'; $url = rtrim($url, '/'); preg_match('/([^\/]*)$/', $url, $match); var_dump($match);
Test