Avatar of pillmill
 asked on

parse_url when url is a paramater?

Parse_url produces the wrong result the one of the parameters is itself a url:

For example,


will lose all of the params after the url parameter, because the "&"
delimiting the parameters is not recognized.

How can I fix this? I need all the parameters from a URL REST query, when
one of the parameter values is itself a URL.  
PHPHTTP ProtocolWeb Development

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Also found this at php.net.  Don't know if it applies to you

URL's in the query string of a relative URL will cause a problem


Ray Paseur

Here is the demonstration script proving that HainKurt is on the ball.

Best to all, ~Ray
<?php // RAY_temp_pillmill.php

$url = 'http://www.hainkurt.com?a=1&b=2';
$enc = urlencode($url);
$new = urldecode($enc);

echo "<pre>";
echo PHP_EOL . htmlentities($url);
echo PHP_EOL . htmlentities($enc);
echo PHP_EOL . htmlentities($new);

Open in new window

Sandeep Kothari

well you have to explode the parse string with & and before doing that you decode the parse string...

example code :

$theurl = "http://www.example.com?h=test&o=ok&urll=http://www.example.org&helo=bye&working=fine";

$param_arr = explode('&',$theurl);


Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Ray Paseur

No points for this, please -- the question has already been answered.  The PHP URL functions are documented here:

These are the PHP functions that make it easy to get this right.

Best to all, ~Ray

I concur with Ray_Paseur that HainKurt's answer is the one to use.  If the variable "query" were a URL such as "http://www.example.com?x=y&z=3", it would have to be passed through urlencode() in order to keep the values for $_GET['x'] and $_GET['z']; without that, it is simply not possible to be 100% sure that all the attached variables (except maybe the first) remain attached to it.

@kshna: please be respectful of other experts. There is no reason that the user asking the question should have to deal with such childish outbursts. Your fix does not actually fix the problem, but merely illustrates the problem: Ray_Paseur was saying "no points" for the post it was stated in, indicating that HainKurt's answer was the one that should be awarded points.