Unescape HTML entities in Javascript?

前端 未结 30 2907
野趣味
野趣味 2020-11-21 05:40

I have some Javascript code that communicates with an XML-RPC backend. The XML-RPC returns strings of the form:


30条回答
  •  隐瞒了意图╮
    2020-11-21 05:50

    a javascript solution that catches the common ones:

    var map = {amp: '&', lt: '<', gt: '>', quot: '"', '#039': "'"}
    str = str.replace(/&([^;]+);/g, (m, c) => map[c])
    

    this is the reverse of https://stackoverflow.com/a/4835406/2738039

提交回复
热议问题