JS Convert HTML escape character

Source: Internet
Author: User

Remove the HTML tag function removehtmltab (tab) {return tab.replace (/<[^<>]+?>/g, ");//delete all HTML tags}// The normal character is converted to the signifier function Html2escape (sHtml) {return shtml.replace (/[<>& "]/g,function (c) {return {' < ': ' < ', ' > ': ' > ', ' & ': ' & ', ' ' ' ': ' ' '}[c ';} Convert the signifier to normal character function escape2html (str) {var arrentities={' lt ': ' < ', ' GT ': ' > ', ' nbsp ': ', ' amp ': ' & ', ' quot ': ' "' }; Return Str.replace (/& (Lt|gt|nbsp|amp|quot);/ig,function (all,t) {return arrentities[t];});   Turn to space function Nbsp2space (str) {var arrentities = {' nbsp ': '}; return Str.replace (/& (nbsp);/ig, function (al L, t) {return arrentities[t]})}//carriage return to BR label function RETURN2BR (str) {return str.replace (/\r?\n/g, "<br/>");} Remove the opening end wrap and convert more than 3 consecutive lines into 2 newline function trimbr (str) {Str=str.replace (/((\s| ) *\r?\n) {3,}/g, "\r\n\r\n");// Limit up to 2 newline Str=str.replace (/^ ((\s| ) *\r?\n) +/g, ');//clear start line-break Str=str.replace (/((\s| ) *\r?\n) +$/g, ');// Clear end wrap return str;} Combine multiple contiguous spaces into a single space function Mergespace (str) {Str=str.repLace (/(\s| ) +/g, '); return str;}

  

JS Convert HTML escape character

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.