Advertisement
livechatinc

JS strip_tags

Oct 16th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function strip_tags(input, allowed) {
  2.   allowed = (((allowed || '') + '')
  3.     .toLowerCase()
  4.     .match(/<[a-z][a-z0-9]*>/g) || [])
  5.     .join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
  6.   var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
  7.     commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
  8.   return input.replace(commentsAndPhpTags, '')
  9.     .replace(tags, function($0, $1) {
  10.       return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
  11.     });
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement