10

I read the reference question urlencode vs rawurlencode? in the way, that I should use rawurlencode

e.g.

If interoperability with other systems is important then it seems rawurlencode is the way to go.

But why was urlencode invented then? Does it mean this function is useless?

Community
  • 1
  • 1
Ryan
  • 10,041
  • 27
  • 91
  • 156
  • I usually use urlencode in all my applications and they all work nicely. It's all about RFC 3986 – AKS Sep 23 '12 at 18:40
  • Why not ask that as a comment on the original answer? I think your question is on the verge of duplicate, if you think it isn't, edit it so it's obvious. – Madara's Ghost Sep 23 '12 at 18:49
  • It was invented for the HTML standards, see RFC1866 (HTML 2.0), in specific here: http://tools.ietf.org/html/rfc1866#section-8.2 - it basically saves network bandwidth for commonly entered text. The space symbol is used quite often within text. Not much of an issue nowadays. – hakre Sep 23 '12 at 19:28
  • Not useless, but it uses special characters and it is often easy to get confused rawurlencode is better – geekman Sep 23 '12 at 18:49

1 Answers1

16

It depends on what you are after. A main difference between them is the standard that they encode to of course, but also spaces.

urlencode encodes the same way that form data is encoded

urlencode encodes spaces as + symbols while rawurlencode encodes them as %20.

Therefore when dealing with form data, urlencode would be preferable (as forms encode spaces as + signs too). Otherwise rawurlencode is a wiser choice in my opinion.

For example, you may want to mimic form data being submitted via a URL, you would use urlencode.

David
  • 2,053
  • 2
  • 16
  • 26
  • ' therefore when dealing with form data, urlencode would be preferable (as forms encode spaces as + signs too). ' - can you explain it with an example ? What is the problem if we use `rawurlencode` here ? – Istiaque Ahmed Jul 19 '19 at 19:08