Created
December 25, 2013 15:27
-
-
Save nasal/8124204 to your computer and use it in GitHub Desktop.
PHP: Change a piece of the URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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