0

How to convert multibyte characters like curly quotes to their equivalent entity like “ using jquery or javascript?

var userTxt = '“testing”';  

after converting userTxt should look like => “testing”

Satish Gadhave
  • 2,660
  • 2
  • 17
  • 27

3 Answers3

0

Here's how to do it:

$('<div/>').text('This is fun & stuff').html(); // evaluates to "This is fun &amp; stuff"

Source

Or you can do it this way.

Kamil Szymański
  • 940
  • 12
  • 26
0

try instead if you can use $quot instead of &#8220

var e_encoded = e.html().replace(/"/g, "&quot;");
console.log(e_encoded); // outputs &quot;&amp;

or you can use this function

function htmlEscape(str) {
    return String(str)
            .replace(/&/g, '&amp;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
}
Tushar Gupta - curioustushar
  • 56,454
  • 22
  • 99
  • 107
0

You can do this using regular expressions.

function replace_quotes( text ){
    return text.replace(/\u201C/g, "&#8220;").replace(/\u201D/g, "&#8221;");
}

This function replaces the quote characters by matching their unicode hex code.
See: Regex Tutorial - Unicode Characters

Splendiferous
  • 733
  • 2
  • 6
  • 17