/ Published in: PHP
Allows you preserve and update a query string and it's existing values easily, instead of constantly appending the new value to the end of the query string
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * Name: Preserve and update/rebuild query string<br> * @param Example: * Example URL: http://www.site.com/?category=foo&order=desc&page=2 * * <a href="<?php echo queryString('order','asc'); ?>">Order ASC</a> * * Output HTML: <a href="?category=foo&order=asc&page=2">Order ASC</a> * Output URL: http://www.site.com/?category=foo&order=asc&page=2 * * Not http://www.site.com/?category=foo&order=desc&page=2&order=asc */ function queryString($str,$val) { $queryString = $_GET; $queryString[$str] = $val; return $queryString; } ?>