Questions tagged [html-encode]

Anything related to encoding or decoding HTML entities.

Specifying the document's character encoding

There are several ways to specify which character encoding is used in the document. First, the web server can include the character encoding or charset in the Hypertext Transfer Protocol () Content-Type header, which would typically look like this:

Content-Type: text/html; charset=ISO-8859-1

This method gives the HTTP server a convenient way to alter document's encoding according to content negotiation; certain HTTP server software can do it, for example Apache with the module mod_charset_lite.

For HTML it is possible to include this information inside the head element near the top of the document:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

also allows the following syntax to mean exactly the same:

<meta charset="utf-8">

Character encoding in HTML: http://en.wikipedia.org/wiki/Character_encodings_in_HTML

599 questions
58
votes
0 answers

how do you do html encode using javascript?

Possible Duplicate: JavaScript/jQuery HTML Encoding I have html tags need to be encoded. test I need to encode it to : <b>test</b> I am using escape, but it doesn't work. document.write(escape("test")); the result I…
qinking126
  • 9,655
  • 20
  • 67
  • 112
49
votes
5 answers

What is the difference between AntiXss.HtmlEncode and HttpUtility.HtmlEncode?

I just ran across a question with an answer suggesting the AntiXss library to avoid cross site scripting. Sounded interesting, reading the msdn blog, it appears to just provide an HtmlEncode() method. But I already use HttpUtility.HtmlEncode(). Why…
g .
  • 7,722
  • 5
  • 34
  • 48
47
votes
7 answers

C# HTMLDecode without System.Web possible?

I know there are different methods in the System.Web namespace for decoding html entities (such as "%20" for space). I'm building a Winforms application however, but needs to deal with html encoded strings. Basically I have the iTunes Library XML…
miccet
  • 1,840
  • 3
  • 19
  • 25
43
votes
5 answers

HTML.Encode but preserve line breaks

I take user input into a text area, store it and eventually display it back to the user. In my View (Razor) I want to do something like this... @Message.Replace("\n", "
") This doesn't work because Razor Html Encodes by default. This is great…
BZink
  • 7,106
  • 10
  • 34
  • 54
43
votes
4 answers

Html encode in PHP

What is the easiest way to Html encode in PHP?
Mathias F
  • 14,815
  • 19
  • 82
  • 151
42
votes
5 answers

How do I bypass the HTML encoding when using Html.ActionLink in Mvc?

Whenever I use Html.ActionLink it always Html encodes my display string. For instance I want my link to look like this: More… it outputs like this: More… &hellip is "..." incase you were…
Micah
  • 101,237
  • 81
  • 221
  • 320
41
votes
6 answers

Converting HTML entities to Unicode Characters in C#

I found similar questions and answers for Python and Javascript, but not for C# or any other WinRT compatible language. The reason I think I need it, is because I'm displaying text I get from websites in a Windows 8 store app. E.g. é should…
Remy
  • 11,899
  • 13
  • 60
  • 97
39
votes
11 answers

Html inside XML. Should I use CDATA or encode the HTML

I am using XML to share HTML content. AFAIK, I could embed the HTML either by: Encoding it: I don't know if it is completely safe to use. And I would have to decode it again. Use CDATA sections: I could still have problems if the content contains…
alberto
  • 543
  • 1
  • 4
  • 7
39
votes
4 answers

How to make Jade stop HTML encoding element attributes, and produce a literal string value?

UPDATE Jade v0.24.0 fixes this with a != syntax for attributes. option(value!='<%= id %>') I'm trying to build an
Derick Bailey
  • 69,055
  • 21
  • 193
  • 207
35
votes
2 answers

HTML Encoding Strings - ASP.NET Web Forms VS Razor View Engine

I'm not quite sure how this works yet... trying to find documentation. In my existing app I've got two different ways of rendering strings in my View <%: model.something %> <%= model.something %> The first one is html encoded, and the…
Chase Florell
  • 42,985
  • 56
  • 169
  • 364
32
votes
7 answers

Is there a JDK class to do HTML encoding (but not URL encoding)?

I am of course familiar with the java.net.URLEncoder and java.net.URLDecoder classes. However, I only need HTML-style encoding. (I don't want ' ' replaced with '+', etc). I am not aware of any JDK built in class that will do just HTML encoding. …
Eddie
  • 51,249
  • 21
  • 117
  • 141
31
votes
4 answers

HTML encode user input when storing or when displaying

Simple question that keeps bugging me. Should I HTML encode user input right away and store the encoded contents in the database, or should I store the raw values and HTML encode when displaying? Storing encoded data greatly reduces the risk of a…
Mark S. Rasmussen
  • 32,298
  • 4
  • 37
  • 56
30
votes
2 answers

PHP html decoding help - converting: A 'quote' is bold

I need to convert a string like this: A 'quote' is bold into: A 'quote' is bold html_entity_decode() did not work.
tzmatt7447
  • 2,099
  • 8
  • 22
  • 30
30
votes
3 answers

How to display HTML stored in a database from an ASP.NET MVC view?

I have HTML code edited by FCKEditor stored in a database and would like to display (well render) it onto a view. So, for instance, something stored as: <>pre<>This is some sample text<>pre</> Will be displayed to the user…
Jedidja
  • 15,384
  • 16
  • 71
  • 109
28
votes
1 answer

With the new Razor View Engine, should my HtmlHelpers return string or IHtmlString?

With the Razor View Engine, anytime you output a string directly to the page, it's HTML encoded. e.g.: @"

Hello World

" will actually get output to the page as: <p>Hello World </p> Which would show up in the browser as:

Hello…

BFree
  • 97,931
  • 20
  • 150
  • 197
1
2
3
39 40