2015-04-17 47 views
0

我送參數鏈接到一個PHP頁面,如:腓獲取參數用&符號

http:// exemple.com/test.php?url=http:// i-want-to-get-this-link.com 

在PHP頁面,我得到這樣的鏈接:

$ _GET ['網址「];

問題一段時間的鏈接有&符號:

http:// exemple.com/test.php?url=http:// i-want-to-get-this-link .com/?page1&desc/otherstaff 

所以我只得到該鏈接的第一部分:http:// i-want-to-get-this-link.com/?page1

我怎麼能拿鏈接其餘&desc/otherstaff

+0

你是否有控制設置'?url'? – Ghost

+0

http://php.net/manual/en/function.urlencode.php嘗試尋找網址編碼。它應該有助於處理您的特殊字符問題。 –

回答

0

可以使用parse_url()函數來得到查詢,如果你無法控制輸入網址。試試這個: print_r(parse_url($_SERVER['REQUEST_URI']));

2

在你的url變量上使用urlencode生成url

<?php 
    $url = 'http:// exemple.com/test.php?url='.urlencode('http://i-want-to-get-this-link.com'); 
?> 

編輯:你不需要用$ _GET和$ _REQUEST變量urldecode。

urldecode獲取原始URL。

<?php 
    $url = urldecode($_GET['url']); 
?> 
+1

看起來像你已經更快:) – mokk

+1

從手冊:'警告 超全球變量$ _GET和$ _REQUEST已經解碼。對$ _GET或$ _REQUEST中的元素使用urldecode()可能會產生意外和危險的結果 – TiiJ7