views:

385

answers:

1

I have some content from feeds. In these feeds, UTF-8 characters are often encoded as character references, ie "å" is "å". To avoid double encoding these in my views (ie "å") I want to convert these back to normal UTF_8 characters. How can I do this in Ruby?

I want:

"å".convert_to_utf8 => "å"

+3  A: 

The HTMLEntities gem is designed to do just this.

require 'htmlentities'
coder = HTMLEntities.new
string = "élan"
coder.decode(string) # => "élan"
# or
string.decode_entities # => "élan"
Chuck
Awesome! Just what I was looking for, thanks.
Christian