Change PHP GET with link? -


i'd create link changes php $_get variable. example:

url: http://site.com/index&variable=hello&anothervariable=dontchangeme  <a href="variable=world">click me</a>  (after click)  url: http://site.com/index&variable=world&anothervariable=dontchangeme 

i know can change page (href="1.html"), i'd same thing while maintaining variables there.

$query = array('variable' => 'world') + $_get;  printf('<a href="index?%s">click me</a>', http_build_query($query)); 

see http://php.net/http_build_query. that's easy understand minimal version. correctly need html-escape generated query string (because you're putting html):

printf('<a href="index?%s">click me</a>', htmlspecialchars(http_build_query($query))); 

Comments