Skip to content

Instantly share code, notes, and snippets.

@mfyz
Created April 9, 2013 04:39
Show Gist options
  • Save mfyz/5343004 to your computer and use it in GitHub Desktop.
Save mfyz/5343004 to your computer and use it in GitHub Desktop.
php update url variables
<?
function update_url($_data, $url = NULL){
if (!$url) $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$_url = parse_url($url);
if (isset($_url['query']) AND $_url['query']) parse_str($_url['query'], $_params);
else $_params = array();
$_updated_params = array_merge($_params, $_data);
$new_url = $_url['scheme'] . '://' . $_url['host'] . $_url['path'];
$new_url .= '?' . http_build_query($_updated_params);
return $new_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment