0

I have some problems with mb_convert_encoding. In the database I have table:

  • topics (latin1_swedish_ci)

Website is in UTF-8. And db connection to MySQL is in UTF-8 too. I can't change connection settings, but I can change db table.

I was thinking that I can double decode it and get UTF-8. For now it's looks like so:

string 'КвеÑты.' (length=27)

And I've tried next solution:

mb_convert_encoding($str, 'Windows-1251', 'UTF-8');

Out:

string '?????�???�?�.' (length=13)

  • Where is the windows charset coming from? Update the DB table to be UTF8 as well. Use utf8 everywhere and you dont need to change the encodings. – chris85 Dec 10 '16 at 16:00
  • Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – chris85 Dec 10 '16 at 16:00
  • If you think you're going to have `utf-8` character set in your table, change the collation of particular column containing `utf-8` characters to `utf8_general_ci` or make the table itself compatible to `utf8_general_ci` therefore this will reflect on all the columns in the table. – Wolverine Dec 10 '16 at 16:03
  • Do not user `mb_convert...`; two 'wrongs' rarely make a 'right'. – Rick James Dec 13 '16 at 01:01
  • Read http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored , especially the part "Test the data". Let us know the result of `SELECT col, HEX(col) ...` -- we need to know if the text was mangled going into the table or coming out. – Rick James Dec 13 '16 at 01:04
  • `Кве`, in utf8 (or utf8mb4) is hex `D09AD0B2D0B5`, which is `Кве` in if Mojibake. Similarly `ты` comes from `ты`. But I don't know about the other two characters in yoru string. Study this, it may have the answer: http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Dec 13 '16 at 01:08
  • You _cannot_ store Cyrillic into a `latin1` column. – Rick James Dec 13 '16 at 01:09

0 Answers0