Reputation: 22509
is it possible that I can only get the clean url with no parameters.
this is an example.
$dis_url = $_SERVER['REQUEST_URI'];
echo $dis_url;
returns into:
'/mysite.com/subdir?message=value&message2=value2'
is it posible that it will return into:
'/mysite.com/subdir'
the parameter will not be included?
does anyone have an idea about my case? thanks in advance...
Upvotes: 1
Views: 8302
Reputation: 56
To add to previous replies.
You can directly get the path from parse_url()
by directly passing the constant PHP_URL_PATH
as second parameter.
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
The variable $uri
will contain the path only '/subdir
'.
From the php manual: PHP:
parse_url()
- Manual
Upvotes: 0
Reputation: 21
str_replace( $_SERVER['REQUEST_QUERY'], '', $_SERVER['REQUEST_URI'] );
Upvotes: 0
Reputation: 4037
Try parse_url()
$parts = parse_url($_SERVER['REQUEST_URI']);
$required = $parts['path'];
Upvotes: 1
Reputation: 41229
Use parse_url() function
<?php
$dis_url ="http://example.com/mobile?u=me";
$url=parse_url($dis_url);
$scheme=$url["scheme"];
$host=$url["host"];
$path=$url["path"];
echo $scheme."://".$host.$path;
?>
Output: http://example.com/mobile
Upvotes: 1
Reputation: 8171
$dis_url = $_SERVER['REQUEST_URI'];
$uri = trim(strtok($dis_url, '?'));
Upvotes: 4
Reputation: 788
$dis_url = $_SERVER["SCRIPT_NAME"];
echo $dis_url;
It will only shows the PHP File name itself.
Upvotes: 0