Guest User

Untitled

a guest
Jan 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. // You need this one.
  2.  
  3. function text2html(str) {
  4. return str
  5. .replace(/\</g, '<')
  6. .replace(/\>/g, '>')
  7. .replace(/\&/g, '&')
  8. .replace(/\&apos;/g, '\'')
  9. .replace(/\"/g, '"');
  10. }
  11.  
  12. // And the opposite, useful for santizing inputs...
  13.  
  14. function html2text(str) {
  15. return str
  16. .replace(/</g, '<')
  17. .replace(/>/g, '>')
  18. .replace(/&/g, '&')
  19. .replace(/'/g, '&apos;')
  20. .replace(/"/g, '"');
  21. }
Add Comment
Please, Sign In to add comment