Difference between Url Encode and HTML encode

前端 未结 5 1220
情书的邮戳
情书的邮戳 2021-01-18 06:52

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

5条回答
  •  猫巷女王i
    2021-01-18 07:31

    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 >

提交回复
热议问题