3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = 'https://www.somehost.com/test/index.html?param1=4&param2=3&param3=2&param4=1&param5=3'; function parse($str) { // parse string to uri array $uri = parse_url($str); // parse query params to array parse_str($uri['query'], $params); // task1. filter params by 3 $params = array_filter($params, function($p) { return (int)$p !== 3; }); // task2. sort params asort($params); // task3. get url $params['url'] = $uri['path']; return $uri['scheme'] . '://' . $uri['host'] . '/?' . http_build_query($params); } echo parse($str);
based on Zm0kd
Output for 5.6.0 - 7.1.0
https://www.somehost.com/?param4=1&param3=2&param1=4&url=%2Ftest%2Findex.html