I receive “incompatible character encodings: CP850 and UTF-8” when displaying the £ symbol on my ramaze app

守給你的承諾、 提交于 2019-12-12 10:43:43

问题


I receive "incompatible character encodings: CP850 and UTF-8" when displaying the £ symbol on my ramaze app. How can I get rid of this error? I have the UTF-8 meta tag in my head tag.

It happens when I type the £ symbol with the keyboard. Look.

I have put the following code in my ruby file and it hasn't fixed the problem.

# encoding: UTF-8 
Encoding.default_external = 'utf-8'
Encoding.default_internal = Encoding::UTF_8

回答1:


Try to force the encoding to see if that makes the problem go away:

your_string.force_encoding(::Encoding::UTF_8)

If it does, dive into your app and spot what is setting the wrong encoding, where, and why.

It's possibly server-/webpage-related, as in the page you're serving is rendered as US-ASCII owing to a header. Or the server is started with encoding other than UTF-8. Or something other to that effect. Your script ends up with a piece of external data that isn't UTF-8.




回答2:


Windows issue? Try using Iconv:

Iconv.conv('utf-8', "WINDOWS-1253", X)



来源:https://stackoverflow.com/questions/31909569/i-receive-incompatible-character-encodings-cp850-and-utf-8-when-displaying-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!