extract last part of a url

前端 未结 5 1755
小鲜肉
小鲜肉 2021-01-05 16:32

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

5条回答
  •  旧时难觅i
    2021-01-05 17:30

    $url = 'http://example.com/i/am/file.php';
    $url = rtrim($url, '/');
    preg_match('/([^\/]*)$/', $url, $match);
    var_dump($match);
    

    Test

提交回复
热议问题