Is ',' bad in the url?

F

FFMG

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/)
 
J

J.O. Aho

FFMG said:
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.
 
F

FFMG

J.O. Aho;107610 said:
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 said:
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/)
 
T

Toby A Inkster

FFMG said:
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/
 
H

Harlan Messinger

FFMG said:
J.O. Aho;107610 said:
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 said:
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.
 
T

Toby A Inkster

Harlan said:
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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top