Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Removed the PHP solution part, pasted JSfiddle code.
Source Link
naivists
  • 33.7k
  • 5
  • 63
  • 85

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; 

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/

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; 
formatting
Source Link
Lucas Trzesniewski
  • 51.6k
  • 11
  • 115
  • 169

parse_url(http://php.net/manual/en/function.parse-url.phpparse_url) to get the query string, parse_Str(http://php.net/manual/en/function.parse-str.phpparse_str) to split the query string in parts, change the necessary parts, then concatenate it back together.

Update: Played with javascriptJavaScript a bit, iI believe this solves your problem: http://jsfiddle.net/dk48vwz7/

parse_url(http://php.net/manual/en/function.parse-url.php) to get the query string, parse_Str(http://php.net/manual/en/function.parse-str.php) 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/

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/

added 109 characters in body
Source Link
naivists
  • 33.7k
  • 5
  • 63
  • 85

parse_url(http://php.net/manual/en/function.parse-url.php) to get the query string, parse_Str(http://php.net/manual/en/function.parse-str.php) 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/

parse_url(http://php.net/manual/en/function.parse-url.php) to get the query string, parse_Str(http://php.net/manual/en/function.parse-str.php) to split the query string in parts, change the necessary parts, then concatenate it back together

parse_url(http://php.net/manual/en/function.parse-url.php) to get the query string, parse_Str(http://php.net/manual/en/function.parse-str.php) 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/

Source Link
naivists
  • 33.7k
  • 5
  • 63
  • 85
Loading