PHP take arguments from URL path

前端 未结 4 2133
南笙
南笙 2021-01-05 14:34

Say I have a url like this:

http://www.mysite.com/forum/board1/sub-forum/topics/123

Is there a simple way in PHP (can\'t use HTAccess) to take t

4条回答
  •  梦毁少年i
    2021-01-05 15:24

    If you already have configured your web server to send those requests to your particular PHP file, you can use parse_url and explode to get and then split the requested URI path into its segments:

    $_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    $pathSegments = explode('/', $_SERVER['REQUEST_URI_PATH']);
    

提交回复
热议问题