0

I have a URL like:

http://www.google.com/test.html?d=1232&u=32

and I want to add it as a part of a GET query string like:

http://www.mysite.com/index.html?a=123&d=http://www.google.com/test.html?d=1232&u=32

Note the double "d" used. I want the URL sent to be just a url and not be read for it's query string...

What is the best way to do this to avoid problems?

4 Answers 4

4

You can use the urlencode() function.

Example:

$url = 'http://www.mysite.com/index.html?a=123&d='
       . urlencode('http://www.google.com/test.html?d=1232&u=32');
Sign up to request clarification or add additional context in comments.

Comments

2

You can use urlencode() to put that in the URL without having it interfere with anything else you have in there.

Comments

1

URL-encode the second url:

http://mysite.com/index.html?a=123&d=<?php echo urlencode('http://google.com/etc..'); ?>

Comments

0

You can assign a url to a variable and have it be query-string safe by using urlencode() (http://us3.php.net/urlencode). So you could do:

$url = 'http://www.mysite.com/index.html?a=123&d=' . urlencode('http://www.google.com/test.html?d=1232&u=32');

In this example the query-string var 'd' now houses all the contents of the second url. You will have to urldecode() it on the receiving end in order to extrapolate the data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.