The StripHtml function strips all the HTML tags in the passed string but preserves the ones specified in the PreserveTags array.
Contextual Ads
More Ruby Resources
Advertisement
- def StripHtml(str, PreserveTags = [‘a’,‘img’,‘p’,‘br’,‘i’,‘b’,‘u’,‘ul’,‘li’])
- str = str.strip || ”
- PreserveArr = PreserveTags.join(‘|’) << ‘|\/’
- str.gsub(/<(\/|\s)*[^(#{PreserveArr})][^>]*>/,”)
- end