Advertisements

J.O. Aho;107610 Wrote:
> FFMG wrote:
> > Hi,
> >
> > I want to use a separator in some queries in the URL
> >
> > http://www.example.com/?k=1,2,3
> >
> > It all works fine but the ',' is converted to the html '%2C', (I use
> > php URLencode, http://php.net/urlencode).
>
> The function do convert the string in the same way as it would be if it
> had
> been posted as application/x-www-form-urlencoded.
>
> The %XX don't change how the data is handled, just looks differently
> and works
> sometimes a lot better than not urlencode the string.
>

Like I said, it all works fine.
My problem is purely from a cosmetic point of view, it looks broken.

FFMG wrote:
> It all works fine but the ',' is converted to the html '%2C', (I use php
> URLencode, http://php.net/urlencode).

The PHP urlencode() function is a little overcautious. It encodes
virtually any non-alphanumeric character in the URL, even though many
would be perfectly safe to leave unencoded.

If you prefer your commas to be unencoded, then I suggest writing your
own replacement for urlencode. It's not difficult.

If you're using PHP 5.3+ with namespaces, then you can even name your
function "urlencode()" too, so that you don't need to go through all your
files replacing calls to urlencode() with my_urlencode().

FFMG wrote:
> J.O. Aho;107610 Wrote:
>> FFMG wrote:
>>> Hi,
>>>
>>> I want to use a separator in some queries in the URL
>>>
>>> http://www.example.com/?k=1,2,3
>>>
>>> It all works fine but the ',' is converted to the html '%2C', (I use
>>> php URLencode, http://php.net/urlencode).
>> The function do convert the string in the same way as it would be if it
>> had
>> been posted as application/x-www-form-urlencoded.
>>
>> The %XX don't change how the data is handled, just looks differently
>> and works
>> sometimes a lot better than not urlencode the string.
>>
>
> Like I said, it all works fine.
> My problem is purely from a cosmetic point of view, it looks broken.
>
> J.O. Aho;107610 Wrote:
>> Use an array instead of one variable.
>>
>
> Do you mean http://www.example.com/?k[0]=1&k[1]=2 ?

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!