Get last word from URL after a slash in PHP

后端 未结 8 1996
囚心锁ツ
囚心锁ツ 2020-12-06 00:50

I need to get the very last word from an URL. So for example I have the following URL:

http://www.mydomainname.com/m/groups/view/test

I need to get with PHP

8条回答
  •  没有蜡笔的小新
    2020-12-06 01:16

    ex: $url      = 'http://www.youtube.com/embed/ADU0QnQ4eDs';
    $url      = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $url_path = parse_url($url, PHP_URL_PATH);
    $basename = pathinfo($url_path, PATHINFO_BASENAME);
    // **output**: $basename is "ADU0QnQ4eDs"
    

    complete solution you will get in the below link. i just found to Get last word from URL after a slash in PHP.

    Get last parameter of url in php

提交回复
热议问题