开发者

Rails 3 encode non ascii?

I'm wondering if there's a helper in rails 3 or a simple way of converting all non ascii characters to their htm开发者_如何转开发l entities. Such as: à to à. ® to ®

The purpose of this is to replace any such characters before exporting to a CSV format. Since viewing the characters in Excel doesn't turn out too well. Worst case scenario I'll just use gsub for each instance, but I'd rather avoid that if possible.


If you can't find anything for Rails then you could check out HTMLEntities:
http://htmlentities.rubyforge.org/

require 'htmlentities'
coder = HTMLEntities.new
string = "<élan>"
coder.encode(string, :named)       # => "&lt;&eacute;lan&gt;"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜