ASP strip_tags function equivalent to PHP


/ Published in: ASP
Save to your folder(s)

This function has also an “allowed tags” parameter as the PHP function to keep some specified tags (the tags to keep must be comma separated). This function is better since you can put allowedTags equal to an empty string to strip all the tags as the first function.


Copy this code and paste it in your HTML
  1. function strip_tags(strHTML, allowedTags)
  2.  
  3. dim objRegExp, strOutput
  4. set objRegExp = new regexp
  5.  
  6. strOutput = strHTML
  7. allowedTags = "," & lcase(replace(allowedTags, " ", "")) & ","
  8.  
  9. objRegExp.IgnoreCase = true
  10. objRegExp.Global = true
  11. objRegExp.MultiLine = true
  12. objRegExp.Pattern = "<(.|\n)+?>"
  13. set matches = objRegExp.execute(strHTML)
  14. objRegExp.Pattern = "<(/?)(\w+)[^>]*>"
  15. for each match in matches
  16. tagName = objRegExp.Replace(match.value, "$2")
  17. if instr(allowedTags, "," & lcase(tagName) & ",") = 0 then
  18. strOutput = replace(strOutput, match.value, "")
  19. end if
  20. next
  21. strip_tags = strOutput
  22. set objRegExp = nothing
  23. end function

URL: http://www.barattalo.it/2010/02/09/asp-strip-tags-function-equivalent-to-php/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.