Posted By

ginoplusio on 02/09/10


Tagged

regexpstriptags


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

ginoplusio
mamona
benrudolph
ByGone
dan74


ASP strip_tags function equivalent to PHP


 / Published in: ASP
 

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

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.

  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

Report this snippet  

You need to login to post a comment.