当前位置: 代码迷 >> HTML/CSS >> Strip_tags掏出html标签
  详细解决方案

Strip_tags掏出html标签

热度:131   发布时间:2012-08-24 10:00:21.0
Strip_tags取出html标签

strip_tags(html)?public

Strips all?HTML?tags from the?html,?including comments. This uses the html-scanner tokenizer and so itsHTML?parsing ability is limited by that of html-scanner.

Examples

strip_tags("Strip <i>these</i> tags!")
# => Strip these tags!

strip_tags("<b>Bold</b> no more!  <a href='more.html'>See more here</a>...")
# => Bold no more!  See more here...

strip_tags("<div id='top-bar'>Welcome to my website!</div>")
# => Welcome to my website!

strip_tags method not functioning in controllers, models, or libs

It comes up with an error about white_list_sanitizer undefined in the class you’re using it in. To get around this, use:

ActionController::Base.helpers.strip_tags('string')

To shorten this, add something like this in an initializer:

class String
  def strip_tags
    ActionController::Base.helpers.strip_tags(self)
  end
end

then call it with:

'string'.strip_tags
  相关解决方案