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

631 questions
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
  • 102,548
  • 21
  • 159
  • 201
27
votes
1 answer

Arabic language in php/mysql appears "????" question marks in html

Possible Duplicate: Save Data in Arabic in MySQL database I have a problem with retrieving Arabic data from MYSQL database using PHP, it appears as question marks "????" in HTML: I have a database with "utf8_general_ci" as collation. The…
CairoCoder
  • 3,091
  • 11
  • 46
  • 68
26
votes
5 answers

ASP.NET MVC Html.Encode - New lines

Html.Encode seems to simply call HttpUtility.HtmlEncode to replace a few html specific characters with their escape sequences. However this doesn't provide any consideration for how new lines and multiple spaces will be interpretted (markup…
David
26
votes
9 answers

How to use HtmlEncode with TemplateFields, Data Binding, and a GridView

I have a GridView bound to an ObjectDataSource. I've got it supporting editing as well, which works just fine. However, I'd like to safely HtmlEncode text that is displayed as we do allow special characters in certain fields. This is a cinch to…
Sean Hanley
  • 5,677
  • 7
  • 42
  • 53
26
votes
3 answers

Turn off HTML Encoding in Razor

I have a function that returns a snippet of JavaScript and/or HTML. static public string SpeakEvil() { return ""; } In the view, Razor is quite rightly HTML encoding it, as most would expect.…
Damien Sawyer
  • 5,323
  • 3
  • 44
  • 56
26
votes
1 answer

Why is my custom HTML Helper result getting html encoded?

I've got the following custom html helper in asp.net mvc 3 public static string RegisterJS(this HtmlHelper helper, ScriptLibrary scriptLib) { return "\r\n"; } The problem is that the result is getting…
Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113
23
votes
5 answers

How to Html.Encode in webforms

I have an ASP.NET Web Forms application. There is a page with TextBoxes and users enter search terms into these which are used to query the database. I know that I need to prevent JavaScript injection attacks. How do I do this? In MVC I would use…
Mr Cricket
  • 5,663
  • 5
  • 22
  • 14
23
votes
4 answers

What do I need to escape inside the html
 tag

I use the
 tag in my blog to post code. I know I have to change < to < and > to >. Are any other characters I need to escape for correct html?
Alec Jacobson
  • 6,032
  • 5
  • 51
  • 88
22
votes
11 answers

How To Replace < with < and > with > using jquery

I have a page that is part of a backend CRM admin panel. On that page the HTML output comes from some PHP functions that I can't access. And that HTML automatically changes < and > into HTML encoded characters. So there is a div that contains html…
sebas
  • 722
  • 1
  • 6
  • 21
22
votes
3 answers

How can I encode a string for HTML?

I'm looking for a simple way to HTML encode a string/object in Perl. The fewer additional packages used the better.
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
20
votes
3 answers

Xml Escaping/Encoding terminology

I'm confused as for the difference between the terms "escaping" and "encoding" in phrases like: Xml Encoding Xml Escaping Encoded Html Escaped Url ... Can anyone explain it to me?
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158
20
votes
1 answer

How to HTML-encode in the JSP expression language?

Consider the following piece of JSP: The value of ${flashVars} contains ampersands and needs to be encoded before it is output. Instead, JSP expects the value of ${flashVars} to be a piece of HTML and…
Martijn
  • 6,713
  • 3
  • 31
  • 38
19
votes
2 answers

html_entity_decode problem in PHP?

I am trying to convert HTML entities from a source string to their literal character equivalent. For example: Whilst this rightly converts the entity on screen,…
mootymoots
  • 4,545
  • 9
  • 46
  • 74
18
votes
2 answers

How does Html.Raw MVC helper work?

I use the Html.Raw to print a raw html content, for example when I send some thing like ViewBag.div = "
Hello
"; from the controller to the view side it does not print a raw html content unless I use the Html.Raw method but if I have an…
Mo Haidar
  • 3,748
  • 6
  • 37
  • 76
18
votes
1 answer

how to encode href attribute in HTML

What should be done against contents of href attribute: HTML or URL encoding? link text On the one hand, since href attribute contains URL I should use URL encoding. On the other hand, I'm inserting this URL into HTML, so it must…
Maksim Tyutmanov
  • 423
  • 1
  • 5
  • 12
1 2
3
42 43