Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Created November 4, 2009 22:44
Show Gist options
  • Save wtnabe/226457 to your computer and use it in GitHub Desktop.
Save wtnabe/226457 to your computer and use it in GitHub Desktop.
A Ruby version of PHP's strip_tags() function
require 'rubygems'
require 'hpricot'
$KCODE = 'u'
def strip_tags( html )
Hpricot( html ).inner_text.gsub( /(?:\xc2\xa0| #  
\xe3\x80\x80| # fullwidth
[\s])+/x, ' ' ).strip
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment