php; remove single variable value pair from querystring

前端 未结 4 2054
醉酒成梦
醉酒成梦 2021-01-17 23:38

I have a page that lists out items according to numerous parameters ie variables with values.

listitems.php?color=green&size=small&cat=pants&pa         


        
4条回答
  •  悲&欢浪女
    2021-01-18 00:03

    It wouldn't work if edit=1 is the first variable:

    listitems.php?edit=1&color=green&...
    

    You can use the $_GET variable to create the query string yourself. Something like:

    $qs = '';
    foreach ($_GET as $key => $value){
        if ($key  == 'pagenum'){
            // Replace page number
            $qs .= $key  . '=' . $new_page_num . '&';
        }elseif ($key  != 'edit'){
            // Keep all key/values, except 'edit'
            $qs .= $key  . '=' . urlencode($value) . '&';
        }
    }
    

提交回复
热议问题