Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

HTML stripper (See related posts)

// description of your code here

str = <<HTML_TEXT


Application error

Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html

HTML_TEXT puts str.gsub(/<\/?[^>]*>/, "")

Comments on this post

jamiew posts on Jan 15, 2008 at 21:11
I also use this from time to time

class String
  def strip_html(allowed = ['a','img','p','br','i','b','u','ul','li'])
        str = self.strip || ''
        str.gsub(/<(\/|\s)*[^(#{allowed.join('|') << '|\/'})][^>]*>/,'')

You need to create an account or log in to post comments to this site.

Related Posts