views:

1114

answers:

5

What’s the difference between an URL Encode and a HTML Encode?

A: 

I don't know what language you are working in, but the PHP manual for example provides good explanations.

URLEncode

Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the » RFC 1738 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs.

Read on

Pekka
A: 

If you want to encode for use in a URL, you use URL encoding.

If you want to encode for display on an HTML page, you HTML encode it

Mitch Wheat
Would the downvoter please leave a comment. This is the same advice as the answer that has 10+ upvotes. Thanks.
Mitch Wheat
+8  A: 

URL encode will encode characters so that they are valid for URLs. E.g. ? becomes %3F

HTML encode will encode characters so they are valid for HTML. E.g. < becomes &lt;

Matt Ellen
+10  A: 

HTML Encoding escapes special characters in strings used in HTML documents to prevent confusion with HTML elements like changing

"<hello>world</hello>"

to

"&lt;hello&gt;world&lt;/hello&gt;"

URL Encoding does a similar thing for string values in a URL like changing

"hello+world = hello world"

to

"hello%2Bworld+%3D+hello+world"
Mehrdad Afshari