DZone 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
Convert Unicode Characters To HTML Entities In Ruby
def entities( str )
converted = []
str.split(//).collect { |c| converted << ( c[0] > 127 ? "#{c[0]};" : c ) }
converted.join('')
end





Comments
Snippets Manager replied on Mon, 2012/05/07 - 2:18pm
str.unpack("U*").collect {|s| (s > 127 ? "&##{s};" : s.chr) }.join(""):)