Last active
August 29, 2015 14:25
-
-
Save JohnnyR030T/8ababc280b9e462e5867 to your computer and use it in GitHub Desktop.
Bonfire: Convert HTML Entities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Convert the characters "&", "<", ">", '"' (double quote), and "'" (apostrophe), in a string to their corresponding HTML entities. | |
| function convert(str) { | |
| if (str.includes('&')){ | |
| str = str.replace('&', '&'); | |
| } | |
| else if (str.includes('<')) { | |
| str = str.replace('<', '<'); | |
| } | |
| else if (str.includes('>')) { | |
| str = str.replace('>', '>'); | |
| } | |
| else if (str.includes('"')) | |
| str = str.replace("'", "&apos"); | |
| return str; | |
| } | |
| convert('Dolce & Gabbana'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment