for example, I have an address:
abc.com/?abc=123&xyz=987
I want to change the abc variable to 456, keep the other variables as they are, and return the new URI address.
the method currently used is regular matching:
function uridis($act,$val){return preg_replace("/(^|&)".$act."\=(?:.*?)($|&)/i","\1".$act."=".$val."\2",$_SERVER["QUERY_STRING"]);}
call in the PHP file:
uridis("abc",456);
if implemented in this way, regular expressions take up about 387KB memory.
and replace with str_replace:
function uridis($act,$val){return trim(str_replace("&".$act."=".$_GET[$act]."&","&".$act."=".$val."&","&".$_SERVER["QUERY_STRING"]."&"),"&");}
takes up more memory, about 392KB. Don"t even think about the cycle $_ GET, you can"t read it at all.
because I need to generate dozens of replaced URI, programs on the page that are very efficient.
so do you have a lighter solution? Thank you very much!