Convert HTML Entities

Source: Internet
Author: User

Converts characters in a string,,, & < > " (double quotation marks), and (single quotation marks) to their corresponding HTML entities.

Correspondence Relationship:https://dev.w3.org/html5/html-author/charref

1 functionCONVERT (str) {2   varobj = {3"&": ' &amp; ',4' < ': ' &lt; ',5">": ' &gt; ',6' "': ' &quot; ',7"'": ' &apos; '8   };9    for(varValinchobj) {    Ten     varReg =NewRegExp (Val, ' G '); One     //a direct substitution replaces only the first occurrence, and the regular expression replaces all items Astr =str.replace (Reg,obj[val]); -   } -    the   returnstr; - } -  -Convert ("Hamburgers < Pizza < Tacos");

Convert HTML Entities

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.