Hey everyone,
This is the function I use when replacing url variables, or adding a new variable.

I realize there are holes but for the most part as long as there are no crazy characters in the url or the variables you will be ok.

PHP Code:
function replaceUrl($url,$uKey,$uVal){
$Qurl explode("?",$url);
$arr explode("&",$Qurl[1]);
$r ''$set 0;
$arr2 explode("=",$arr[$i]);
$arr2[0] == $uKey){
$arr2[1] = $uVal;
$set 1;
$set == 0){
$r.= $uKey."=".$uVal;
    } else {
$r rtrim($r"&");


PHP Code:

print replaceUrl('http://yourDomain.com/index.php?test=1&name=rlemon&age=19','name','rob lemon');