What characters should be escaped with their HTML entities. For example, & is escaped with &.
Should ' be escaped with '?
|
What characters should be escaped with their HTML entities. For example, Should |
||||
|
|
|
I don't have comment privileges, or I would have left this as a comment on an earlier answer. DO NOT, I repeat, DO NOT escape an apostrophe in HTML using
This is not a valid HTML character entity reference. It is an XML character entity reference. While Firefox and Chrome, at least, will render the above as an apostrophe in an HTML document, Internet Explorer will not. And it is following the standard when it refuses to do so. You may escape an apostrophe in HTML using
But I don't believe it is, in general, necessary. http://fishbowl.pastiche.org/2003/07/01/the_curse_of_apos/ http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references |
|||
|
|
|
I don't agree with Nate. You should ideally use as little escaping as possible and use UTF-8 to express characters natively. To do this you need an editor that can handle UTF-8 as well as a correct charset declaration, such as:
However, you should make it a habit to escape the characters that have a special meaning in (X)HTML, namely:
This will make sure you're not accidentally writing markup when you want to write these characters. This is especially important for user input, to maintain security. It's less obvious, but it's actually important to escape If you're using PHP, you can use the Update: I stand corrected on the apos issue. Damned pesky IE. |
|||||||
|
|
The easiest way to do the job without using the actual entity is to use PHP's
|
|||||
|