JS Convert HTML escape character

Source: Internet
Author: User

//Remove HTML Tagsfunctionremovehtmltab (tab) {returnTab.replace (/<[^<>]+?>/g, ");//Delete all HTML tags}//convert ordinary characters to a signifierfunctionHtml2escape (sHtml) {returnShtml.replace (/[<>& "]/g,function(c) {return{' < ': ' &lt; ', ' > ': ' &gt; ', ' & ': ' &amp; ', ' ' ': ' &quot; '}[c];});}//Convert the signifier to ordinary charactersfunctionescape2html (str) {vararrentities={' lt ': ' < ', ' GT ': ' > ', ' nbsp ': ', ' amp ': ' & ', ' quot ': ' "'}; returnStr.replace (/& (Lt|gt|nbsp|amp|quot);/ig,function(all,t) {returnarrentities[t];});}//&nbsp; turn into spacesfunctionNbsp2space (str) {varArrentities = {' nbsp ': '}; returnStr.replace (/& (nbsp);/ig,function(All, T) {returnarrentities[t]})}//return to BR labelfunctionreturn2br (str) {returnStr.replace (/\r?\n/g, "<br/>");}//Remove the opening end wrap and convert more than 3 consecutive lines to 2 line breaksfunctiontrimbr (str) {str=str.replace (/((\s|&nbsp;) *\r?\n) {3,}/g, "\r\n\r\n");//limit up to 2 line breaksStr=str.replace (/^ ((\s|&nbsp;) *\r?\n) +/g, ');//Clear start line breakStr=str.replace (/((\s|&nbsp;) *\r?\n) +$/g, ');//Clear End Line wrapping returnstr;}//combine multiple contiguous spaces into a single spacefunctionMergespace (str) {str=str.replace (/(\s|&nbsp;) +/g, "); returnstr;}

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.