Best way to add / change 1 GET value while saving others?

How can I create a link that simply adds or modifies 1 GET var while keeping everyone else?

I have a page created using different GET vars.

So it will be like mypage.php?color=red&size=7&brand=some%20brand

So, I want to have a link that sets it to page = 2 or size = 8. What is the easiest way to have a link to do this without transferring all the other options?

I hope this makes sense let me know if I need to explain something else

+5
source share
2 answers

You can parse the parse_str url to get the url values. Then you can create an HTTP request using http_build_query :

$query_arr = $_GET; //or parse_str($_SERVER['QUERY_STRING'], $query_arr)
$query_arr["page"] = 2;
$query_arr["size"] = 8;

$query = http_build_query($query_arr);

EDIT: , ... parse_str(), .

+7

All Articles