Hi,
I am trying to get the last slash (/xxx/) out of http://XXX.example.com/xxx/ and just appear as "xxx"
Get Part Of a URL
Moderator: General Moderators
Re: Get Part Of a URL
You're going to need to give us more information. What is this for? How does your application work? Are you talking about redirecting from /xxx/ to /xxx ? Give us more info.
Re: Get Part Of a URL
Try this: $_SERVER superglobal
You may be looking for REQUEST_URI (that's URI, not URL).
This would return 'xxx' given the example URL you provided:
You may be looking for REQUEST_URI (that's URI, not URL).
This would return 'xxx' given the example URL you provided:
Code: Select all
str_replace('/', '', $_SERVER['REQUEST_URI']);Re: Get Part Of a URL
If the url is not the same as the REQUEST_URI, you can use `parse_url()` then use `trim()`
Code: Select all
$path = parse_url("http://XXX.example.com/xxx/", PHP_URL_PATH);
$path = trim($path, "/");
echo $path; // xxx