How can I get the current web directory from the URL?

后端 未结 5 912
[愿得一人]
[愿得一人] 2021-01-28 03:09

If I have a URL that is http://www.example.com/sites/dir/index.html, I would want to extract the word \"sites\". I know I have to use regular expressions but for some reason my

5条回答
  •  爱一瞬间的悲伤
    2021-01-28 03:20

    Use the dirname function like this:

    $dir =  dirname($_SERVER['PHP_SELF']);
    $dirs = explode('/', $dir);
    echo $dirs[0]; // get first dir
    

提交回复
热议问题