Get last word from URL after a slash in PHP

后端 未结 8 1970
囚心锁ツ
囚心锁ツ 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:25

    by using regex:

    preg_match("/[^\/]+$/", "http://www.mydomainname.com/m/groups/view/test", $matches);
    $last_word = $matches[0]; // test
    
    0 讨论(0)
  • 2020-12-06 01:25

    I used this:

    $lastWord = substr($url, strrpos($url, '/') + 1);
    

    Thnx to: https://stackoverflow.com/a/1361752/4189000

    0 讨论(0)
提交回复
热议问题