Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to get and edit GET variables in order to make hyperlinks

Let's say that I have URL like somefile.php?sort=id&way=desc.

I want to write a function (or use already made one) that would let me add next variables to URL and set which I want to delete.

I thought about something like function editGetVar("$add","$leave") where $add would be array with new variables to add to URL and $leave would be array with variables that must stay in URL.

Example:

somefile.php?sort=id&way=desc&buyer=retailer

and I want to delete "buyer" and add "action", then the a href would look like this:

<a href="somefile.php?sort=id&way=desc&action=edit">

I would appreciate any ideas from you.

like image 223
jwitos Avatar asked Mar 03 '11 16:03

jwitos


People also ask

How to put Variable in URL?

To add a URL variable to each link, go to the Advanced tab of the link editor. In the URL Variables field, you will enter a variable and value pair like so: variable=value. For example, let's say we are creating links for each store and manager.


1 Answers

Use http_build_query:

<?php
unset($_GET['buyer']);
$_GET['action'] = 'edit';

print '<a href="somefile.php?' . http_build_query($_GET) . '">!!</a>';
?>
like image 160
Lightness Races in Orbit Avatar answered Oct 12 '22 23:10

Lightness Races in Orbit