Erik Edgren Erik Edgren - 7 months ago 31
PHP Question

parse_url replacing the plus sign with a space

$url = parse_url('');
$address = ltrim(rtrim($url['path'], '/'), '/');
echo $address;

outputs erikedgren
. Why? And how can I solve this problem?


The code above outputs
. But when I replace the address in
), I get 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:

The last part with the extern address, is what
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.