Per farlo puoi usare:

https://www.php.net/parse_url
https://www.php.net/parse_str
https://www.php.net/http_build_query