Reputation: 9340
Well... Html pages and mysql tables contain cyrillic text. For displaying the cyrillic text Барысаў2000 I use
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
on the web-page. For storing that word in MySQL table, utf8_unicode_ci collation is used (I've read some topics and, as I understand, utf8_unicode_ci is recommended for storing cyrillic symbols). But, what I actually see using phpMyAdmin, the text Барысаў2000 is stored as Áàðûñà¢2000 in the db, and that's the problem I wish to solve. (POST method + escaping dangerous symbols are used to save user's text into db). But, when you SELECT that data and display it on the html page, it looks fine: Барысаў2000.
The problem how phpMyAdmin displays it for me didn't bother me until today. Today I've tried to solve it.
I guessed I have to use utf-8 everywhere, so I switched from
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
to
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
Now my pages display questions instead of cyrillic symbols and the question with displayng cyrillic text in my db was not solved. Who can tell me what's the problem? P.S. I can read serbian and belarusian (cyrillic languages) web-sites without any problems and can type cyrillic texts on my localhost.
Thank you.
Upvotes: 0
Views: 4317
Reputation: 13976
Problem with phpMyAdmin is probably caused by incorrect character encoding guessing. If you encode the text Барысаў2000
using charset windows 1251
you'll end up having a byte stream C1 E0 F0 FB F1 E0 A2 32 30 30 30 0D 0A
. If this byte stream is interpreted as text that with ISO-8859-1 or windows-1252 encoding, the result is shown as Áàðûñà¢2000
.
This suggests that the strings in your database are really stored with windows-1251 encoding. Then if you output these strings and only claim that it uses UTF-8 encoding (without doing any recoding), the result will be garbage text because that byte stream contains invalid UTF-8 byte sequences.
You should either continue serving your pages with windows-1251 charset and tell phpMyAdmin to use this charset too or you should switch to unicode everywhere (also internally, in the database). The less character conversions and guessing the proper encoding you need, the easier it will be to maintain your system.
Upvotes: 2