PHP: How to remove specific query string from a url?

There are many ways via which this can be achieved, some of the tested code is written below:

The following function will remove only the query string you want to remove:

function removeqsvar($url, $varname) {
    list($urlpart, $qspart) = array_pad(explode('?', $url), 2, '');
    parse_str($qspart, $qsvars);
    $newqs = http_build_query($qsvars); return $urlpart . '?' . $newqs; 

Example Use:

echo removeqsvar('','date');

If you have a better code to achieve above, please leave it as a comment so we all experiment together : )

You may also like...