Showing posts with label How to Add/Replace GET parameters in url PHP. Show all posts
Showing posts with label How to Add/Replace GET parameters in url PHP. Show all posts

Saturday 4 November 2017

How to append GET parameters in url PHP

First make one function like below

$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$param = GET;

function filter_url($url,$param){

    $parsed = parse_url($url);
    $query = str_replace("&","&",$parsed['query']);
    parse_str($query,$params);
    unset($params[$param]);
    $new_query = http_build_query($params);
    $newUrl = $parsed['scheme']."://".$parsed['host'].$parsed['path'];
    if($new_query){
        $newUrl .= "?".$new_query;
    }
    return $newUrl;

}