I am using PHP scripting.
I have an URL like http://example.com?tag=test1&creative=165953&creativeASIN=B07BH2N15X&linkCode=df0&ascsubtag=test2. In the query string, tag=test1 and ascsubtag=test2, I know the values test1 & test2 not the key. Now I want to remove the keys tag & ascsubtag from the URL for sensitization purpose.
Expected output is http://example.com?creative=165953&creativeASIN=B07BH2N15X&linkCode=df0. How can I achieve this in simple way.
I have tried the following code,
$a = parse_url("http://example.com?tag=test1&creative=165953&creativeASIN=B07BH2N15X&linkCode=df0&ascsubtag=test2");
parse_str($a['query'], $queryStr);
$interchanged = array_flip($queryStr);
unset($interchanged['test1']);
unset($interchanged['test2']);
echo $a['scheme'] . "://" . $a['host'] . (isset($pURL['path']) ? $pURL['path'] : '') . "?" . http_build_query(array_flip($interchanged));
Is there any other way to achieve this?