开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜