/    Sign up×
Community /Pin to ProfileBookmark

Split query string = + and &

Hi

I have this script that splits the query string, removing the = and &

…search=my+query&….., so leaving my+query.

Howver, can anyone suggest how I can split the query string further, so that “my+query”, becomes “my” “query”

TIA

[CODE]<script language=”javascript” type=”text/javascript”>
<!–
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split(“&”);
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split(“=”);
if (pair[0] == variable) {
return pair[1];
}
}
}
// –>
</script>[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 03.2006 — &lt;script type="text/javascript"&gt;

qs = 'fee=fie&amp;foe=fum&amp;further=foo+bar'

String.prototype.splitQueryString = function () {return this.split (/[=+&amp;]/)}

alert (qs.splitQueryString())

&lt;/script&gt;
Copy linkTweet thisAlerts:
@dbobauthorDec 03.2006 — Great, but i've gotta ask the usual question expected from a newbie.... :o How do I amend this to the script posted?

sos
Copy linkTweet thisAlerts:
@CharlesDec 03.2006 — For the most part you replace your script with that. But I'm not sure exactly what you are trying to accomplish by also splitting on the "+" characters. You will no longer have key value pairs.
×

Success!

Help @dbob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...