Use this function to add current values to the QUERY_STRING.


Rebuild query string ver. 1.03

updated: 2006-05-10
I modified some code created by Macromedia Dreamweaver into a flexible function to rebuild the query string. The function is very useful for pagination or passing variables from one page to another.In this version it's possible to add more than one variable names into the functions arguments. This names will be filtered from the new generated query string. Just add the variable names you don't need into a comma seperated string.

Viewed 19090 times

Rating: script rated with stars
 

Your banner at finalwebsites.com?
use the contact form for further information and prices.

<?php
function rebuild_qs($curr_vars) {
    if (!empty($_SERVER['QUERY_STRING'])) {
        $parts = explode("&", $_SERVER['QUERY_STRING']);
        $curr_vars = str_replace(" ", "", $curr_vars); // remove whitespace
        $c_vars = explode(",", $curr_vars);
        $newParts = array();
        foreach ($parts as $val) {
            $val_parts = explode("=", $val);
            if (!in_array($val_parts[0], $c_vars)) {
                array_push($newParts, $val);
            }
        }
        if (count($newParts) != 0) {
            $qs = "&".implode("&", $newParts);
        } else {
            return false;
        }
        return $qs; // this is your new created query string
    } else {
        return false;
    }
}
/* Example:
script.php?ident=1<?php echo rebuild_qs("ident, submit, var_one"); ?> */

?>