3v4l.org

run code in 300+ PHP versions simultaneously
<?php function removeVar($url, $key) { $url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&'); $url = substr($url, 0, -1); return $url; } $url = "/search/listing.html?vehicle_type=&year=&make_name=&model_name=&loc_type=3&zipcode=641004&distance=100&make_order=ASC"; $newUrl = removeVar($url, "distance"); echo $newUrl;

preferences:
34.34 ms | 402 KiB | 5 Q