how to convert &#(no); embedded in a string to a string with corresponding character in javascript?
how to convert &#(no); embedded in a string to a string with correspo开发者_如何学编程nding character in javascript?
theString.replace(/&#x([0-9a-f]+);/ig, function(s, code) {
return String.fromCharCode(parseInt(code, 16));
})
Similar for decimal (&#(\d+);).
For entities (©) you need a look-up table.
Why not just directly display the string as HTML anyway? Just strip all the < and > if you want to avoid XSS.
加载中,请稍侯......
精彩评论