Welcome Guest, Not a member yet? Register   Sign In
Encoding problem
#29

[eluser]snifty[/eluser]
The content is coming up okay for me in both Firefox and Chrome (Mac), but FF thinks that the page is Unicode, whereas Chrome thinks it's Latin-1.

The bytes in the page actually *are* encoded in Latin-1, as this Python session will demonstrate:

Code:
>>> import urllib
>>> html = urllib.urlopen('http://79.125.116.38/').read()
>>> h4 =  [line for line in html.splitlines() if 'h4' in line][0]
>>> print h4
            <h4>Guldet p? v?g mot toppen</h4>
>>> print h4.decode('latin-1')
            <h4>Guldet på väg mot toppen</h4>

My terminal is set to UTF-8, so as you can see when I try to print it, the UTF-8 encoding can't recognize the non-ASCII bits. But if I decode it from Latin-1 (into the default, UTF-8), and then print the result, it shows up ok.

The point of all this is that despite what the headers in your file and anything else says, what you're getting out of your db is still Latin-1 (ISO-8859-1).

I can understand why you would want to try to make your whole app be Latin-1 if you have a ton of content in your database, but if it's a small amount of content you might consider trying to convert the whole thing to UTF-8, it's going to make your life easier in the future...

Is the fact that you have a ton of content encoded as Latin-1 what's keeping you from using UTF-8? Unicode is really the path of least resistance these days...


Messages In This Thread
Encoding problem - by El Forum - 05-29-2011, 03:09 AM
Encoding problem - by El Forum - 05-29-2011, 03:24 AM
Encoding problem - by El Forum - 05-29-2011, 04:41 AM
Encoding problem - by El Forum - 05-29-2011, 05:18 AM
Encoding problem - by El Forum - 05-29-2011, 05:49 AM
Encoding problem - by El Forum - 05-29-2011, 07:06 PM
Encoding problem - by El Forum - 05-29-2011, 10:44 PM
Encoding problem - by El Forum - 05-29-2011, 10:58 PM
Encoding problem - by El Forum - 05-30-2011, 01:54 AM
Encoding problem - by El Forum - 05-30-2011, 04:14 AM
Encoding problem - by El Forum - 05-30-2011, 11:03 AM
Encoding problem - by El Forum - 05-30-2011, 05:14 PM
Encoding problem - by El Forum - 05-30-2011, 07:50 PM
Encoding problem - by El Forum - 05-31-2011, 01:31 AM
Encoding problem - by El Forum - 05-31-2011, 01:53 AM
Encoding problem - by El Forum - 05-31-2011, 02:11 AM
Encoding problem - by El Forum - 05-31-2011, 02:30 AM
Encoding problem - by El Forum - 05-31-2011, 02:36 AM
Encoding problem - by El Forum - 05-31-2011, 02:37 AM
Encoding problem - by El Forum - 05-31-2011, 02:43 AM
Encoding problem - by El Forum - 05-31-2011, 02:47 AM
Encoding problem - by El Forum - 05-31-2011, 02:51 AM
Encoding problem - by El Forum - 05-31-2011, 02:54 AM
Encoding problem - by El Forum - 05-31-2011, 02:56 AM
Encoding problem - by El Forum - 05-31-2011, 02:59 AM
Encoding problem - by El Forum - 05-31-2011, 03:02 AM
Encoding problem - by El Forum - 05-31-2011, 03:05 AM
Encoding problem - by El Forum - 05-31-2011, 03:12 AM
Encoding problem - by El Forum - 05-31-2011, 03:15 AM
Encoding problem - by El Forum - 05-31-2011, 03:18 AM
Encoding problem - by El Forum - 05-31-2011, 03:25 AM
Encoding problem - by El Forum - 05-31-2011, 03:40 AM
Encoding problem - by El Forum - 05-31-2011, 04:13 AM
Encoding problem - by El Forum - 06-07-2011, 02:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB