PHP比爆炸更快的东西从URL获取文件名

My URL's can be absolute or relative:

$rel = "date/album/001.jpg";
$abs = "http://www.site.com/date/album/image.jpg";

function getFilename($url) {
    $imgName = explode("/", $url);
    $imgName = $imgName[count($imgName) - 1];
    echo $imgName;
}

There must be a faster way to do this right? Maybe a reg expression? But that's Chinese to me..

basename returns the file name:

function getFilename($url) {
    return basename($url);
}

You can even strip the file name extension.

substr( $url , strrpos( $url , "/" ) + 1 );

or

substr( strrchr( $url , "/" ) , 1 );

I believe basename is the quickest one, but you can also use

$url = "http://www.mmrahman.co.uk/image/bg830293.jpg";
getFileName($url){
    $parts = pathinfo($url);
    return $parts['basename'];
}

pathinfo also allow you to get filename, extension, dirname etc.