Php 如何删除URL上的参数
我有这个网址 [HTTP\u REFERER]=> 我想把它转换成 我目前正在使用:Php 如何删除URL上的参数,php,url,Php,Url,我有这个网址 [HTTP\u REFERER]=> 我想把它转换成 我目前正在使用: $parse = parse_url($_SERVER['HTTP_REFERER']); $path = http_build_url($_SERVER['HTTP_REFERER'], array( "scheme" => $parse['scheme'], "host" => $parse['host'],
$parse = parse_url($_SERVER['HTTP_REFERER']);
$path = http_build_url($_SERVER['HTTP_REFERER'],
array(
"scheme" => $parse['scheme'],
"host" => $parse['host'],
"path" => $parse['path'],
"query" => " "
),
HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT
);
给我这个错误:致命错误:调用未定义的函数http\u build\u url()。
是否有其他方法可以在不必设置http\u build\u url()的情况下执行此操作?请尝试以下方法:
function getURLWithoutParams($url) {
//Getting the position of ? as it is the start of the parameters
$position = strpos($url, "?");
//strpos returns false if the search yielded no results. If it is not
//false, then we need to extract the needed part, as the url has parameters
if ($position !== false) {
return substr($url, 0, strpos($url, "?"));
}
return $url;
}
用
getURLWithoutParams($\u SERVER['HTTP\u REFERER'])调用它。
这不是javascript-可能是PHP?@EdHeal-Yup,对此表示抱歉。它应该是php:)在php手册上,它说它需要PECL-PECL\u http>=0.21.0
。如果您有权访问服务器,您需要安装它,如果没有,请联系您的主机提供商,您提供的功能不会返回。它为您返回了什么?