Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中从URL中删除特定参数?_Php - Fatal编程技术网

如何在PHP中从URL中删除特定参数?

如何在PHP中从URL中删除特定参数?,php,Php,例如: $url = http://example.com/?arg=val&arg2=test&arv3=testing&arv2=val2 remove_url_arg($url, "arg2") echo($url); // http://example.com/?arg=val&arv3=testing 上述remove\u url\u arg()函数从url中删除所有出现的arg2参数 unset($_GET['arg2']); $query_st

例如:

$url = http://example.com/?arg=val&arg2=test&arv3=testing&arv2=val2  
remove_url_arg($url, "arg2")
echo($url); // http://example.com/?arg=val&arv3=testing
上述
remove\u url\u arg
()函数从url中删除所有出现的
arg2
参数

unset($_GET['arg2']);
$query_string = http_build_query($_GET);
如果不是按请求而是解析整个url

$parsed = parse_url($url);
$qs_arr = parse_str($parsed['query'],1);
unset($qs_arr['arg2']);
$parsed['query'] = http_build_query($qs_arr);
然后重新组装url

或一行正则表达式