note 104896 deleted from function.http-build-query by danbrown

From: Date: Fri, 15 Jul 2011 14:23:16 +0000
Subject: note 104896 deleted from function.http-build-query by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181570@lists.php.net to get a copy of this message
Note Submitter: ic_johnsson ---- 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

« previous php.notes (#181570) next »