php 去掉url中 某个参数

[pcsh lang="php" tab_size="4" message="" hl_lines="" provider="manual"]

function unset_param($param, $url) {
    $param = explode(',', $param);
    foreach ($param as $key => $value) {
        $url = preg_replace(
            array("/\?{$value}=[^&]*/i","/&{$value}=[^&]*/i", '/[&]+/', '/\?[&]+/', '/[?&]+$/',),
            array('?','','&','?','',),
            $url
        );
    }

    return $url;
}

[/pcsh]

多个参数用逗号分隔

 

此处评论已关闭