Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meant by htmlencode and urlencode? [duplicate]

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

like image 507
Quintin Par Avatar asked Nov 28 '09 12:11

Quintin Par


People also ask

What is the difference between HtmlEncode and Urlencode?

HTMLEncoding turns this character into "<" which is the encoded representation of the less-than sign. URLEncoding does the same, but for URLs, for which the special characters are different, although there is some overlap.

What is Urlencode used for?

Why do we need to encode? URLs can only have certain characters from the standard 128 character ASCII set. Reserved characters that do not belong to this set must be encoded. This means that we need to encode these characters when passing into a URL.

What is Server HtmlEncode?

The ASP Server. HTMLEncode() Method is used to convert an HTML code to a string. It is used to encode form data and other client request data before using it in the web application.

What is Urlencode and UrlDecode in PHP?

Another function called the urldecode() function is another inbuilt function of PHP and is implemented for decoding the URL, encoded by the urlencode() function. Decoding is the approach of reversing the non-ASCII data back to its original form. This function will accept a single string as its parameter.


5 Answers

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

like image 21
Pekka Avatar answered Nov 10 '22 00:11

Pekka


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"
like image 76
mmx Avatar answered Nov 10 '22 00:11

mmx


urlEncode replaces special characters with characters that can be understood by web browsers/web servers for the purpose of addressing... hence URL. For instance, spaces are replaced with %20, ' = %27 etc...

See these references:

  • http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
  • http://www.degraeve.com/reference/urlencoding.php

HtmlEncode replaces special characters with character strings that are recognised by the HTML engine itself to render the content of the page - things like & become &amp; or < = &lt;, > = &gt; this prevents the HTML engine from interpreting these characters as parts of the HTML markup and therefore render them as if they were strings.

See this reference:

  • http://msdn.microsoft.com/en-us/library/ms525347.aspx
like image 32
BenAlabaster Avatar answered Nov 10 '22 01:11

BenAlabaster


Both HTML and URL's are essentially very constrained languages. As a language they add meaning to specific keywords or operators. For both of these languages though, keywords are almost always single characters. For example

  • HTML: > and <
  • URL: / and :

In the use of each language though it is possible to use these constructs in a manner that does not ensure the meaning of the language. For instance this post contains a > character. I do not want it to be interpreted as HTML, just text.

This is where Encode and Decode methods come into play. These methods will respectively take a string and convert any of the characters that would otherwise be treated as keywords into an escaped form which will not be interpreted as part of the language.

For instance: Passing > into HtmlEncode will return &gt;

like image 36
JaredPar Avatar answered Nov 09 '22 23:11

JaredPar


HTMLEncode and URLEncode deal with invalid characters in HTML and URLs, or more accurately, characters that need to be specially written to be interpreted correctly. For example, in HTML the < and > characters are used to indicate tags. Thus, if you wanted to write a math formula, something like 1+1 < 2+2, the '<' would normally be interpreted as the beginning of a tag. HTMLEncoding turns this character into "&lt;" which is the encoded representation of the less-than sign. URLEncoding does the same, but for URLs, for which the special characters are different, although there is some overlap.

like image 42
Michael Bray Avatar answered Nov 10 '22 00:11

Michael Bray