php; remove single variable value pair from querystring

前端 未结 4 2053
醉酒成梦
醉酒成梦 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:00

    Another solution, to avoid & problems too!!!

    remove_query('http://example.com/?a=valueWith**&**inside&b=value');
    

    Code:

    function remove_query($url, $which_argument=false){ 
        return preg_replace('/'. ($which_argument ? '(\&|)'.$which_argument.'(\=(.*?)((?=&(?!amp\;))|$)|(.*?)\b)' : '(\?.*)').'/i' , '', $url);  
    }
    

提交回复
热议问题