Home  >  Article  >  Web Front-end  >  The background builds the html string and passes it to the front-end string transcoding (html) processing_html/css_WEB-ITnose

The background builds the html string and passes it to the front-end string transcoding (html) processing_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:43:381492browse

知识在于总结,那就记下了吧!

 

例如后台 html 字符串是

var htmlStr="后台html字符串";

转码

var html格式代码=decodeHtml(htmlStr);

只需调用下面这个js方法就行了

 function decodeHtml(s) {        var HTML_DECODE = {            "&lt;": "<",            "&gt;": ">",            "&amp;": "&",            " ": " ",            "&quot;": "\"",            "&copy;": ""            // Add more        };        var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;        var REGX_HTML_DECODE = /&\w+;|&#(\d+);/g;        var REGX_TRIM = /(^\s*)|(\s*$)/g;        s = (s != undefined) ? s : "";        return (typeof s != "string") ? s :            s.replace(REGX_HTML_DECODE,                      function ($0, $1) {                          var c = HTML_DECODE[$0];                          if (c == undefined) {                              // Maybe is Entity Number                              if (!isNaN($1)) {                                  c = String.fromCharCode(($1 == 160) ? 32 : $1);                              } else {                                  c = $0;                              }                          }                          return c;                      });    };

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn