A have a little problem with an url parameter.
I have a a form which uses method GET as I am only retrieving some data to get a resultlist. The data are not in any way secret to anyone. In short I can in the form input some measurements on a roof and those numbers will be used to calculated how many rooftiles etc. I have to buy. In the form I can also input a percentage of extra rooftiles to be calculated, f.x. 3% extra. After ending the input and pressing calculated I will get an url that look like this:
index.php?page=matliste&width=8&length=12&angle-1=45&extra=3&zip=9000&tagfod=tagfod&finish_stone=dv&topsten=utop&angle=45&mainhouse=1&house=1&rooftype=uu&lang=dk&rooftiletype=1&rid=1&producent=h
In this I have 3% extra. But when I go back to the form and input f.x. 5% it will not be updated. It just inserts a new parameter so it will look something like this:
extra=5&extra=3
How can I remove the existing parameter and insert a new one with the new number?
I am using this to build the query from the form fields:
if($_GET["newpage"] == "matliste") {
$get_elements = array_filter($_GET, "strlen");
$url = http_build_query($get_elements);
$search_pattern = array();
$search_pattern[0] = "/([?&]newpage)=[^&]*/";
$search_pattern[1] = "/([?&]next)=[^&]*/";
$search_pattern[2] = "/angle_\d+/";
$search_replacements = array();
$search_replacements[0] = '';
$search_replacements[1] = '';
$search_replacements[2] = 'angle';
$new_url = preg_replace($search_pattern, $search_replacements, $url);
header("Location: index.php?page=". $_GET["newpage"] ."&".$new_url);
}