How to get everything after the domain name into a string

前端 未结 2 1657
花落未央
花落未央 2020-12-21 01:39

My goal is to get everything after the domain name into a string. As in mysite.com/page/page2 would result in a string \"page/page2\". That I can do, however it starts givin

2条回答
  •  心在旅途
    2020-12-21 01:48

    You could use $_SERVER['REQUEST_URI'] and then modify the string with PHP's substr() function. So, put the URI into a variable and then run that function to remove the first X number of characters (domain name length) from the beginning and X number of characters from the end (index.php = 9).

    For example:

    $new_url = substr($uri_variable, 10, -9);

    Where $uri_variable is the $_SERVER[REQUEST_URI']`, 10 is the character after the domain name and -9 is the characters in index.php.

    https://www.php.net/manual/en/reserved.variables.server.php http://php.net/manual/en/function.substr.php

提交回复
热议问题