Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You need this one.
- function text2html(str) {
- return str
- .replace(/\</g, '<')
- .replace(/\>/g, '>')
- .replace(/\&/g, '&')
- .replace(/\'/g, '\'')
- .replace(/\"/g, '"');
- }
- // And the opposite, useful for santizing inputs...
- function html2text(str) {
- return str
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/&/g, '&')
- .replace(/'/g, ''')
- .replace(/"/g, '"');
- }
Add Comment
Please, Sign In to add comment