我有一些来自Feed的内容。在这些馈送中,UTF-8字符通常被编码为字符引用,即“å”是“å”。为了避免在我的视图中对这些进行双重编码(即“& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp我怎么能在Ruby中做到这一点?
我想:
“å”。convert_to_utf8 => “A”
答案 0 :(得分:6)
HTMLEntities gem旨在实现这一目标。
require 'htmlentities'
coder = HTMLEntities.new
string = "élan"
coder.decode(string) # => "élan"
# or
string.decode_entities # => "élan"