parse_url to get the query string, parse_str to split the query string in parts, change the necessary parts, then concatenate it back together.
Update: Played with JavaScript a bit, I believe this solves your problem: http://jsfiddle.net/dk48vwz7/
var linktext = "http://site/some-url/trends.cgi?createimage&t1=1412757517&t2=1412843917&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=0&initialassumedservicestate=0&assumestateretention=yes&includesoftstates=no&host=SCP-3&service=MODIFICATION+TIME+EDR+FILES&backtrack=4&zoom=4"; //we'll use an in-memory "hyperlink" object for basic parsing var anchor = document.createElement("A"); anchor.href=linktext; //the query string starts with ?, we remove it. //then, split it by & symbol var queryvars = anchor.search.replace(/^\?/, '').split('&'); //now looping through all parts of query string, creating an object in form key->value var querycontent = {}; for( i = 0; i < queryvars.length; i++ ) { var queryvar = queryvars[i].split('='); querycontent[queryvar[0]] = queryvar[1]; } //this allows us to reference parts of the query as properties of "querycontent" variable querycontent.service = "AnotherService" //TODO: change the properties you actually need //and now putting it all back together var querymerged = []; var g = ""; for (var key in querycontent){ var fragment = key; if (querycontent[key]) { fragment += "=" + querycontent[key]; } querymerged.push(fragment); } anchor.search = querymerged.join("&") //finally, access the `href` property of anchor to get the link you need document.getElementById("test").innerText=anchor.href;