Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8456187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:28:57+00:00 2026-06-10T12:28:57+00:00

Assuming www.mydomain.com?param1=example as an example. What is the best way to store a second

  • 0

Assuming www.mydomain.com?param1=example as an example.

What is the best way to store a second parameter that is a list of key value pairs? At the minute I use &param2=key|value,key|value. I separate the key from the value using a vertical line, and the pairing with a comma, everything after the equals is encoded using encodeURIComponent(). This works fine.

However, the user has control of the value… And as sensible human beings we all know that the first thing the user will probably do is stick a vertical bar or a comma as one of the values breaking my parameter parser. Is there a better way to do this? I’ve seen PHP users talking about storing associated arrays in urls but I’m looking for a pure javascript solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:28:59+00:00Added an answer on June 10, 2026 at 12:28 pm

    PHP (and other server-side languages) support passing arrays in the query string.

    www.mydomain.com?param1=example&param2[key1]=value1&param2[key2]=value2
    

    PHP will parse the GET string as such:

    array(2) {
      ["param1"]=>
      string(7) "example"
      ["param2"]=>
      array(2) {
        ["key1"]=>
        string(6) "value1"
        ["key2"]=>
        string(6) "value2"
      }
    }
    

    If you don’t pass keys, it will be become a numeric array:

    www.mydomain.com?param1=example&param2[]=value1&param2[]=value2
    

    Will be parsed as:

    array(2) {
      ["param1"]=>
      string(7) "example"
      ["param2"]=>
      array(2) {
        [0]=>
        string(6) "value1"
        [1]=>
        string(6) "value2"
      }
    }
    

    UPDATE: You can also parse the query string in JavaScript.

    Here is a simple jQuery plugin I made:

    $.parseQuery = function(str) {
        var ret = {};
        $.each(str.split("&"), function() {
            var data = this.split('='),
                name = decodeURIComponent(data.shift()),
                val = decodeURIComponent(data.join("=")).replace('+', ' '),
                nameVal = name.match(/(.*)\[(.*)\]/);
    
            if (nameVal === null) {
                ret[name] = val;
            }
            else {
                name = nameVal[1];
                nameVal = nameVal[2];
                if (!ret[name]) {
                    ret[name] = nameVal ? {} : [];
                }
                if ($.isPlainObject(ret[name])) {
                    ret[name][nameVal] = val;
                }
                else if($.isArray(ret[name])){
                    ret[name].push(val);
                }
            }
        });
        return ret;
    };
    

    Then you can do: $.parseQuery('param1=example&param2[]=value1&param2[]=value2');.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming a URL of: www.example.com/?val=1#part2 PHP can read the request variables val1 using the
I have the following timestamp: 1342259667654 which when converted with http://www.epochconverter.com/ gives: Assuming that
Assuming I have an Amazon product URL like so http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C/ref=amb_link_86123711_2?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-1&pf_rd_r=0AY9N5GXRYHCADJP5P0V&pf_rd_t=101&pf_rd_p=500528151&pf_rd_i=507846 How could I scrape
Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base
I am trying to utilize the example cited here: http://www.physicsforums.com/showthread.php?t=248191 I wrote a simple
I just installed WordPress in a subfolder on my site (http://www.example.com/wordpress/) and I want
I'm binding some items to a menu. Assuming, my site address is www.abc.com/Dev, the
I understand that there's an nginx configuration file at http://www.friendfeed.com But i don't really
I have a text file that contains meta-urls in the following form: http://www.xyz.com/.*services/ http://www.xyz.com/.*/wireless
http://www.therapistsurvey.com/vignette0/vig01 Notice that once you click the See Parents' Response, the link will trigger

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.