Get last word from URL after a slash in PHP

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

    use preg*

    if ( preg_match( "~/(.*?)$~msi", $_SERVER[ "REQUEST_URI" ], $vv ))
     echo $vv[1];
    else
     echo "Nothing here";
    

    this was just idea of code. It can be rewriten in function.

    PS. Generally i use mod_rewrite to handle this... ans process in php the $_GET variables. And this is good practice, IMHO

提交回复
热议问题