Skip to content

Instantly share code, notes, and snippets.

@nasal
Created December 25, 2013 15:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasal/8124204 to your computer and use it in GitHub Desktop.
Save nasal/8124204 to your computer and use it in GitHub Desktop.
PHP: Change a piece of the URL
function changepiece($parameter, $value)
{
$params = array();
$output = "?";
$firstRun = true;
foreach($_GET as $key=>$val)
{
if($key != $parameter)
{
if(!$firstRun)
{
$output .= "&";
}
else
{
$firstRun = false;
}
$output .= $key."=".urlencode($val);
}
}
if(!$firstRun)
$output .= "&";
$output .= $parameter."=".urlencode($value);
return htmlentities($output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment