Background build HTML string to foreground string transcoding (HTML) processing

Source: Internet
Author: User

Knowledge is summed up, then write it down!

For example, the background HTML string is

var htmlstr= "background html string";

transcoding

var HTML format Code =decodehtml (HTMLSTR);

Just call the following JS method on the line

 functiondecodehtml (s) {varHtml_decode = {            "&lt;": "<",            "&gt;": ">",            "&amp;": "&",            "&nbsp;": "",            "&quot;": "\" ",            "&copy;": ""//Add More        }; varRegx_html_encode =/"|&|" | <|>| [\x00-\x20]| [\x7f-\xff]| [\u0100-\u2700]/G; varRegx_html_decode =/&\w+;|&# (\d+);G; varRegx_trim =/(^\s*) | (\s*$)/G; S= (s! = undefined)? S: ""; return(typeofs! = "string")?s:s.replace (Regx_html_decode,function($ A, $) {                          varc = html_decode[$0]; if(c = =undefined) {                              //Maybe is Entity number                              if(!isnan ($) ) {C= String.fromCharCode (($ = = 160)? 32: $); } Else{C= $; }                          }                          returnC;    }); };
View Code

Background build HTML string to foreground string transcoding (HTML) processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.