Welcome to WebmasterWorld Guest from 126.96.36.199
My problem is how to parse a URL that contains multiple GET variables. I have not been able to come up with a universal solution that can update variables that are already in the url, or add them to the url if they don't exist. I've tried using preg_replace, and that seems to work with single replacements, but my systems are getting more complicated, and they don't work all the time.
Is there a PHP function or custom function that can help me out?
If you want to alter a $_GET variable, alter it directly in the $_GET array. This keeps them all in once nice and tidy place.
Then to get your new full URL, use a function that takes the URL you want and adds to it all the $_GET variables, e.g.
function fullURL($url = "/")
foreach($_GET as $key => $value)
$url .= strpos($url, "?") === false ? "?" : "&";
$url .= $key . "=" . $value;
So the use would be like,
<a href="<?php echo fullURL("/test/page.php"); ?>">My Link</a>
Like I said, someone probably knows a better way, I just came up with this!