2012-09-09 68 views
1

從網址獲取網址我有拿到2個參數$鏈接和$文字 我想獲得的所有參數$鏈接參數裏面例如PHP通過get方法

test.php的?鏈接= www.google PHP頁面.COM?測試=測試&測試2 = test2的&文本= testtext

我想獲得鏈接= 'www.google.com?test=test &測試2 = test2的' 和獲取文本= testtext

我使用這個PHP腳本

<?php 

     $text = $_GET['text']; 
     $link = $_GET['link']; 

     echo $text; 
     echo $link; 

?> 

output 

testtext 
www.google.com?test=test 
+0

你的問題是什麼? – LonelyWebCrawler

回答

3

你應該使用它之前把你的編碼參數。

echo '<a href="test.php?link=' . urlencode('www.google.com?test=test&test2=test2') . '&text=' . urlencode('testtext') . '">test</a>'; 

以這種方式,谷歌股票和你的股票之間沒有衝突。細節請參閱urlencode()手冊。

0

如果你想傳遞一個URL作爲參數,你必須轉義它。否則參數將在您的腳本中顯示爲$_GET參數。

你必須使用生成您的urlencode()鏈接:

$link = "test.php?link=".urlencode("www.google.com?test=test&test2=test2")."&text=" . urlencode("testtext"); 

使用字符串時,還可以使用引號:

$text = $_GET['text']; 
$link = $_GET['link']; 
0
$link_mod = str_replace("?", "&", $_GET['link']); 
$array = explode("&", $link_mod); 
unset($array[0]); #get rid of www.google.com segment 
$segments = array(); 
foreach ($array as $line) { 
    $line_array = explode('=', $line); 
    $key = $line_array[0]; 
    $value = $line_array[1]; 
    $segments[$key] = $value; 
} 
print_r($segments);