2011-11-02 90 views
0

我有這樣一個URL:PHP URL使用GET

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

,我想將其添加爲一個GET查詢字符串等的一部分:

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

注雙「 d」使用。我希望URL發送只是一個網址,不能被它的查詢字符串讀取...

什麼是最好的方法來做到這一點,以避免問題?

回答

0

您可以通過使用urlencode()(http://us3.php.net/urlencode)將url指定給變量並使其成爲查詢字符串安全。所以,你可以這樣做:

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

在這個例子中,查詢字符串變種「D」現在房子的第二個URL中的所有內容。你將不得不urldecode()它在接收端,以推斷數據。

4

可以使用功能。

例子:

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

您可以使用urlencode()把URL中,而無需將其與其他任何你在那裏有干擾。