$url = parse_url('https://plus.google.com/+erikedgren');
$address = ltrim(rtrim($url['path'], '/'), '/');
echo $address;
$address
outputs plus.google.com/ erikedgren
. Why? And how can I solve this problem?
EDIT
The code above outputs +erikedgren
. But when I replace the address in $url
with $_GET['u']
(from parse_url(https://plu...)
to parse_url($_GET['u'])
), I get plus.google.com/ erikedgren
. Let me explain how my system works.
When I click on a link on my website on my local server (I haven't released the update yet), the URL for extern addresses looks like this: http://192.168.1.135/erik-edgren/url/https://plus.google.com/+erikedgren
.
The last part with the extern address, is what $_GET['u']
is fetching. Here's how the RewriteRule looks like for it: RewriteRule ^url/(.*)$ get-url.php?u=$ 1
(no spaces between $ and 1).
Based on your updated question, this appears to work for me:
$url = parse_url($_GET['u']);
$address = trim(rawurldecode(urlencode($url['path'])), '/');
echo $address;
I also replaced ltrim
and rtrim
, since trim
will remove from both the beginning and end.