Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urlencode() + or %20?

Status
Not open for further replies.

alphacooler

Programmer
Aug 29, 2005
73
US
Which is correct to have in URL's? +'s or %20 for spaces? I thought %20 was the correct way, but urlencode is giving me +'s instead.

Thanks.
 
Actually, since URLs are not supposed to have spaces in them and using %20 is just a workaround of that limitation, I should think the best solution is to not have spaces in your URLs at all.


Want the best answers? Ask the best questions! TANSTAAFL!
 
I feel very uneasy to see each and every one of the opinions contrary to what I would consider correct---so I am no longer sure. All the consideration and implementation of the url encoding are based on the rfc1738.
Maybe there are other ways of reading the same document after all.
 
I would consider + be the proper url encoding (though putting %20 is equivalent to considering space as "unprintable" leads to no adversity). I would consider having space in a url a normal course of business and hence encoding is required as it is considered "unsafe" in the specific sense documented in the rfc1738.
 
@tsuji: I read rfc1738 as saying that spaces are not allowed in urls but if you must have them they should be encoded as an octet using %20.

i have not tested this (or looked it up) but i believe (from cross references and comments in the php manual) tha the POST method of transferring data (x- does use a '+' to show spaces.

Excerpts from the RFC
Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.

Characters can be unsafe for a number of reasons. The space
character is unsafe ...

All unsafe characters must always be encoded within a URL

octets may be encoded by a character triplet consisting
of the character "%" followed by the two hexadecimal digits (from
"0123456789ABCDEF") which forming the hexadecimal value of the octet
 
I don't know what to say, jpadie. Did I really have said bare space is allowed? I only said it should be encoded. I also meant to say space is not to avoid in the sense of it having to be worked around, in response to slepnir214. I meant it arises as a normal course of business and is to be encoded to be properly transmitted and to locate the resource.

If you search google, typing in "php forum" in the textbox and search, the page holding the resource would be this.
If again you type in the "php forum" (double space) and press the search button, it would return the page.
If you instead manually edit the address,
you get the same page as the first.

No special effort is needed particularly to "avoid" the space(s), it arises in the normal course of business.

This is what I meant.
 
i probably wasn't clear in my language usage. i did not mean to infer that you said spaces were allowed.

my intention was to say that the rfc that you quoted as (I thought) supporting your use of a plus sign as a space in fact requires that %20 is used if a space is included for any reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top