php通过get方法从url获取url
我有一个php页面,包含两个参数$link和$text 我想获取$link参数,其中包含所有参数示例 test.php?link=www.google.com?test=test&test2=test2&text=testtext 我想要获取链接='www.google.com?test=test&test2=test2' 和get text=testtext 我使用这个php脚本php通过get方法从url获取url,php,post,parameters,get,Php,Post,Parameters,Get,我有一个php页面,包含两个参数$link和$text 我想获取$link参数,其中包含所有参数示例 test.php?link=www.google.com?test=test&test2=test2&text=testtext 我想要获取链接='www.google.com?test=test&test2=test2' 和get text=testtext 我使用这个php脚本 <?php $text = $_GET['text']; $link = $_G
<?php
$text = $_GET['text'];
$link = $_GET['link'];
echo $text;
echo $link;
?>
output
testtext
www.google.com?test=test
输出
测试文本
www.google.com?test=test
如果要将URL作为参数传递,必须将其转义。否则,参数将在脚本中显示为$\u GET
参数
您必须使用urlencode()
生成链接:
使用字符串时也要使用引号:
$text = $_GET['text'];
$link = $_GET['link'];
在GET上使用参数之前,应该对其进行编码
echo '<a href="test.php?link=' . urlencode('www.google.com?test=test&test2=test2') . '&text=' . urlencode('testtext') . '">test</a>';
echo';
这样,google VAR和您的VAR之间就没有冲突
有关详细信息,请参阅手册
$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);
echo '<a href="test.php?link=' . urlencode('www.google.com?test=test&test2=test2') . '&text=' . urlencode('testtext') . '">test</a>';