HtmlSpecialChars equivalent in Javascript?

后端 未结 16 1546
耶瑟儿~
耶瑟儿~ 2020-11-22 06:00

Apparently, this is harder to find than I thought it would be. And it even is so simple...

Is there a function equivalent to PHP\'s htmlspecialchars built into Javas

16条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 06:28

    Reversed one:

    function decodeHtml(text) {
        return text
            .replace(/&/g, '&')
            .replace(/</ , '<')
            .replace(/>/, '>')
            .replace(/"/g,'"')
            .replace(/'/g,"'");
    }
    

提交回复
热议问题