Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I escape a single quote?

Tags:

html

escaping

You could use HTML entities:

  • ' for '
  • " for "
  • ...

For more, you can take a look at Character entity references in HTML.


You can use ' (which is iffy in IE) or ' (which should work everywhere). For a comprehensive list, see the W3C HTML5 Named Character References or the HTML entities table on WebPlatform.org.


As you’re in the context of HTML, you need to use HTML to represent that character. And for HTML you need to use a numeric character reference ' (' hexadecimal):

<input type='text' id='abc' value='hel&#39;lo'>

Represent it as a text entity (ASCII 39):

<input type='text' id='abc' value='hel&#39;lo'>

Probably the easiest way:

<input type='text' id='abc' value="hel'lo">