Is ',' bad in the url?

Discussion in 'HTML' started by FFMG, Dec 8, 2007.

  1. FFMG

    FFMG Guest

    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).

    Why is that? I see many sites that don't convert the ',' in their
    links, (sky.com for example).
    Should I not bother converting comas as well?

    What would be a better way of listing items in the URL?

    Thanks

    FFMG


    --

    'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
    (http://www.journalhome.com/) | 'webmaster Directory'
    (http://www.webhostshunter.com/)
    'Recreation Vehicle insurance'
    (http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
    redirection service' (http://urlkick.com/)
    ------------------------------------------------------------------------
    FFMG's Profile: http://www.httppoint.com/member.php?userid=580
    View this thread: http://www.httppoint.com/showthread.php?t=22996

    Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).
    FFMG, Dec 8, 2007
    #1
    1. Advertising

  2. FFMG

    J.O. Aho Guest

    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.


    > What would be a better way of listing items in the URL?


    Use an array instead of one variable.


    --

    //Aho
    J.O. Aho, Dec 8, 2007
    #2
    1. Advertising

  3. FFMG

    FFMG Guest

    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 ?

    FFMG


    --

    'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
    (http://www.journalhome.com/) | 'webmaster Directory'
    (http://www.webhostshunter.com/)
    'Recreation Vehicle insurance'
    (http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
    redirection service' (http://urlkick.com/)
    ------------------------------------------------------------------------
    FFMG's Profile: http://www.httppoint.com/member.php?userid=580
    View this thread: http://www.httppoint.com/showthread.php?t=22996

    Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).
    FFMG, Dec 8, 2007
    #3
  4. 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().

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 23:40.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
    Toby A Inkster, Dec 8, 2007
    #4
  5. 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 ?


    In ASP, at least,

    http://www.example.com/?k=1&k=2&k=3

    will result in Request("k") being an array with three values. Perhaps in
    PHP too.
    Harlan Messinger, Dec 8, 2007
    #5
  6. Harlan Messinger wrote:

    > In ASP, at least,
    >
    > http://www.example.com/?k=1&k=2&k=3
    >
    > will result in Request("k") being an array with three values. Perhaps in
    > PHP too.


    The equivalent in PHP is:

    http://www.example.com/?k[]=1&k[]=2&k[]=3

    k=1&k=2&k=3 will result in $_GET['k'] being '3'. Of course, one can
    always manually parse $_SERVER['QUERY_STRING'] to get the full list out.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 3:15.]

    Sharing Music with Apple iTunes
    http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
    Toby A Inkster, Dec 8, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    850
  2. Eric Anderson

    Bad Transform or Bad Engine?

    Eric Anderson, Oct 4, 2005, in forum: XML
    Replies:
    1
    Views:
    364
    Peter Flynn
    Oct 5, 2005
  3. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    vs2005 publish website doing bad things, bad things

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    587
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 25, 2006
  4. Gene

    Re: Bad code or bad compiler?

    Gene, Jun 1, 2008, in forum: C Programming
    Replies:
    3
    Views:
    272
    Barry Schwarz
    Jun 1, 2008
  5. rantingrick
    Replies:
    44
    Views:
    1,172
    Peter Pearson
    Jul 13, 2010
Loading...

Share This Page