I am trying to send a classic GET request to an API : http://mywebsite.com?arg1=val1&arg2=val2. The problem is I don't know what to do if val1 or val2 contains a "&" or "?" character. I know the urlencode() function but I'm not sure it would help in this case as there needs to be a difference between the "&" used to separate the arguments and the "&" contained by the arguments.
Can anyone help? Thanks
it worked well, I was using simple encode/decode which in general ignores ! or any other special symbol. base64_encode does this.
I finally found a much simpler solution. urlencode() did the trick:
Thank you all for your replies.
if you pass these variables manually, you should urlencode(), if not, browser will do this for you automatically.
Also, for PHP side, no need to urldecode() because PHP will do it for $_GET, $_COOKIE, $_POST
I would personally do this:
In your API you will do:
Perhaps you could try to use
http_build_query()
.http://php.net/http_build_query