Url query - using a key with multiple values I am trying to build a url with a query using the url() function.

    $options = array(
        'query' =&gt; array(
                'parameter1' =&gt; 'value1',
                'parameter2' =&gt; 'value1,value2',
        ),
        'absolute' =&gt; TRUE,
        'external' =&gt; TRUE,
    );
    url ('https://somesite.com/', $options);


The URL becomes: https://somesite.com/?parameter1=value1&amp;parameter2=value1%2Cvalue2

So commas become encoded as %2C. 

How can I build a query that has parameters with multiple values separated by comma?

EDIT: I have to deal with an old API that does not recognize %2C as comma characters, so actual commas have to be present in the end url.
How can I build a query that has parameters with multiple values separated by comma?


You already have, the commas are just encoded so they can be transported safely as part of the URL.

If you mean how can you stop the url() function from encoding special characters: you can't, without editing it. More specifically, you would need to replace its use of drupal_http_build_query with something that only selectively encodes special characters, much like drupal_http_build_query does itself for the / character.

The other options you have are


Do a string replace on the return value from url (or parse it and build it up again to your own spec)
Roll your own url function to your own spec
Contact the maintainers of the API and ask them to fix their decoding bug. Obviously YMMV on that.