解析Url,检查参数,然后再次构建:
$url = "http://localhost/sarkari/wp-login.php?action=logout&redirect_to=%2Fsarkari%2F&_wpnonce=b5e3b954df&redirect_to=http://localhost/sarkari/2017/06/01/new-sample-post/";
function trimUrlParams($url, array $params)
{
$parts = parse_url($url);
parse_str($parts[\'query\'], $query);
$newQuery = array();
if (is_array($query) && sizeof($query) > 0 ) {
foreach ($query as $variable=>$value) {
if (in_array($variable, $params)) {
$newQuery[$variable] = $value;
}
}
}
return $parts[\'scheme\']."://".$parts[\'host\'].$parts[\'path\']."?". http_build_query($newQuery);
}
$newUrl = trimUrlParams($url, array(\'action\', \'redirect_to\', \'_wpnonce\'));