$url = "https://example.com/search?q=keyword&category=books"; $query_params = parse_url($url, PHP_URL_QUERY); parse_str($query_params, $params); print_r($params);
$url = "https://example.com/search?q=keyword&category=books"; $host = parse_url($url, PHP_URL_HOST); $protocol = parse_url($url, PHP_URL_SCHEME); echo "$protocol://$host";
$url = "https://example.com/search"; $params = array("q" => "keyword", "category" => "books"); $query_string = http_build_query($params); $final_url = $url . "?" . $query_string; echo $final_url;Output: https://example.com/search?q=keyword&category=books Therefore, the "Uri" package library could be used to perform these and many more actions on URLs in a PHP web application.