Ok .. so basically, let's say we have a link:
$url = "http://www.site.com/index.php?sub=Mawson&state=QLD&cat=4&page=2&sort=z";
Basically, I need to create a function that replaces every thing in the URL, for example:
<a href="<?=$url;?>?sort=a">Sort by AZ</a> <a href="<?=$url;?>?sort=z">Sort by ZA</a>
Or, for another example:
<a href="<?=$url;?>?cat=1">Category 1</a> <a href="<?=$url;?>?cat=2">Category 2</a>
Or, another example:
<a href="<?=$url;?>?page=1">1</a> <a href="<?=$url;?>?page=2">2</a> <a href="<?=$url;?>?page=3">3</a> <a href="<?=$url;?>?page=4">4</a>
Basically, we need a function that will replace a specific $_GET URL so that we don't get a duplicate, for example ?page=2&page=3
Having said that, he must be smart, so he knows if the beginning of the parameter is ? or &
We also need it to be smart so that we can have a URL like this:
<a href="<?=$url;?>page=3">3</a> (without the ? - so it will detect automatically wether to use an `&` or a `?`
I don't mind creating different variables for each preg_replace for certain $ _GET parameters, but I'm looking for a better way to do this.
Thanks.
source share