获取和编辑GET变量以创建超链接的方式 [英] Way to get and edit GET variables in order to make hyperlinks
问题描述
假设我的网址类似于 somefile.php?sort = id& way = desc
。
我想写一个函数(或者使用已经创建的函数)来让我添加下一个变量到URL并设置我想要删除的。
我想过类似 function editGetVar($ add,$ leave)
其中 $ add
到URL和 $ leave
将会是数组,其变量必须保留在URL中。
$ b 示例:
somefile.php?sort = id& way = desc& buyer = retailer
,我想删除买家并添加action,那么 a href
看起来像这样:
< a href =somefile.php?sort = id& way = desc& action = edit>
如果您有任何想法,我将不胜感激。
使用 http_build_query :
<?php
unset ($ _GET [ '买方']);
$ _GET ['action'] ='edit';
print'< a href =somefile.php?'。http_build_query($ _ GET)。'> !!< / a>';
?>
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.
Use http_build_query:
<?php
unset($_GET['buyer']);
$_GET['action'] = 'edit';
print '<a href="somefile.php?' . http_build_query($_GET) . '">!!</a>';
?>
这篇关于获取和编辑GET变量以创建超链接的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!