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”
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”
Here's how to do it:
$('<div/>').text('This is fun & stuff').html(); // evaluates to "This is fun & stuff"
Or you can do it this way.
try instead if you can use $quot
instead of “
var e_encoded = e.html().replace(/"/g, """);
console.log(e_encoded); // outputs "&
or you can use this function
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
You can do this using regular expressions.
function replace_quotes( text ){
return text.replace(/\u201C/g, "“").replace(/\u201D/g, "”");
}
This function replaces the quote characters by matching their unicode hex code.
See: Regex Tutorial - Unicode Characters