note 104896 added to function.http-build-query
| From: | ic_johnsson at osu1 dot php dot net | Date: | Thu, 14 Jul 2011 12:52:43 +0000 |
| Subject: | note 104896 added to function.http-build-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181497@lists.php.net to get a copy of this message | ||
From the earlier post, I found that if you wan't to change an existing key, you would want to
replace instead of adding the arrays together.
Here is a good function.
<?php
function change_url($key,$value) {
$edit_url = http_build_query(array_replace($_GET, Array($key=>$value)));
return "?".$edit_url;
}
?>
Example1:
Used with
<?php
echo '<a href="'.change_url("site", "start").'">
Start </a>';
echo '<a href="'.change_url("site", "news").'">
News </a>';
?>
you will get two links which both edits the key called "site" in the url:
myhost/?site=start
myhost/?site=blog
Example2:
myhost/?foo=bar&site=start&id=4
Used with
<?php
echo '<a href="'.change_url("foo", "taadoo").'">
Taadoo </a>';
?>
you will get this:
myhost/?foo=taadoo&site=start&id=4
----
Server IP: 69.147.83.197
Probable Submitter: 212.181.38.136
----
Manual Page -- http://www.php.net/manual/en/function.http-build-query.php
Edit -- https://master.php.net/note/edit/104896
Del: integrated -- https://master.php.net/note/delete/104896/integrated
Del: useless -- https://master.php.net/note/delete/104896/useless
Del: bad code -- https://master.php.net/note/delete/104896/bad+code
Del: spam -- https://master.php.net/note/delete/104896/spam
Del: non-english -- https://master.php.net/note/delete/104896/non-english
Del: in docs -- https://master.php.net/note/delete/104896/in+docs
Del: other reasons-- https://master.php.net/note/delete/104896
Reject -- https://master.php.net/note/reject/104896
Search -- https://master.php.net/manage/user-notes.php