How to escape apostrophe (‘) in MySql?

The MySQL documentation you cite actually says a little bit more than you mention. It also says, A “’” inside a string quoted with “’” may be written as “””. (Also, you linked to the MySQL 5.0 version of Table 8.1. Special Character Escape Sequences, and the current version is 5.6 — but the current … Read more

What is the HtmlSpecialChars equivalent in JavaScript?

There is a problem with your solution code–it will only escape the first occurrence of each special character. For example: escapeHtml(‘Kip\’s <b>evil</b> “test” code\’s here’); Actual: Kip&#039;s &lt;b&gt;evil</b> &quot;test” code’s here Expected: Kip&#039;s &lt;b&gt;evil&lt;/b&gt; &quot;test&quot; code&#039;s here Here is code that works properly: function escapeHtml(text) { return text .replace(/&/g, “&amp;”) .replace(/</g, “&lt;”) .replace(/>/g, “&gt;”) .replace(/”/g, … Read more

How do I escape a single quote ( ‘ ) in JavaScript? [duplicate]

You should always consider what the browser will see by the end. In this case, it will see this: <img src=”https://stackoverflow.com/questions/16134910/something” onmouseover=”change(” ex1′)’ /> In other words, the “onmouseover” attribute is just change(, and there’s another “attribute” called ex1′)’ with no value. The truth is, HTML does not use \ for an escape character. But … Read more

Can I convert a C# string value to an escaped string literal?

A long time ago, I found this: private static string ToLiteral(string input) { using (var writer = new StringWriter()) { using (var provider = CodeDomProvider.CreateProvider(“CSharp”)) { provider.GenerateCodeFromExpression(new CodePrimitiveExpression(input), writer, null); return writer.ToString(); } } } This code: var input = “\tHello\r\n\tWorld!”; Console.WriteLine(input); Console.WriteLine(ToLiteral(input)); Produces: Hello World! “\tHello\r\n\tWorld!” These days, Graham discovered you can use Roslyn’s … Read more