0

I want to change my entire system from windows-1257 to utf-8 encoding..
But i'm facing some problems,
When I change AddDefaultCharset from windows-1257 to utf-8 (in .htaccess)

  • It changes from (I want utf-8 result like this):
    enter image description here
    Mūsdienu civilizētajā pasaulē par valsti spriež pēc tā, kā tajā izturas pret saviem visneaizsargātākajiem sabiedrības locekļiem.


  • To this:
    enter image description here
    M�sdienu civiliz�taj� pasaul� par valsti sprie� p�c t�, k� taj� izturas pret saviem visneaizsarg�t�kajiem sabiedr�bas locek�iem.


HTML meta tag can be windows-1257 and UTF-8 (now it's utf-8) - it works fine with AddDefaultCharset windows-1257

In database content looks like this: Mûsdienu civilizçtajâ pasaulç par valsti sprieþ pçc tâ, kâ tajâ izturas pret saviem visneaizsargâtâkajiem sabiedrîbas locekïiem.


I've tried:

  • Change content in database with iconv
  • Alter database/table + "CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;" (Maybe I used the functions wrong..)

Thank you for your time!

Peter
  • 221
  • 1
  • 2
  • 12
  • `AddDefaultCharset` and/or the meta charset just tell the client what encoding your data is supposedly in. You also need to actually *output* data in that encoding, otherwise you get a mismatch (as you see). Mostly you need to save your source code in UTF-8 if it contains any "exotic" (non-ASCII) characters and you need to retrieve your data from the database in UTF-8 by setting the **connection encoding.** – deceze Feb 04 '15 at 09:20
  • @deceze I added `mysql_query("SET character_set_connection = 'UTF8'") or die(mysql_error());` to database file and `AddDefaultCharset utf-8` to .htaccess - as you said.. but still output is "M�sdienu ..." – Peter Feb 04 '15 at 10:32
  • That call is incorrect, the charset is not a string. Also, use `mysql_set_charset('utf8')`. – deceze Feb 04 '15 at 10:56
  • @deceze Oh.. now it outputs it like it's in database.. `Mûsdienu civilizçtajâ pasaulç par valsti sprieþ pçc tâ, kâ tajâ izturas pret saviem visneaizsargâtâkajiem sabiedrîbas locekïiem` – Peter Feb 04 '15 at 10:59
  • 1
    You may be interested in: [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Feb 04 '15 at 11:04
  • @deceze so, texts are stored in `latin1`, i can make them work by setting `Content-Type` to `windows-1257`.. but the thing is - if it's in `latin1` in database, it's unreal to get `ûçâ` as `ūēā` with `utf-8` on `Content-Type`? – Peter Feb 04 '15 at 11:43
  • How the data is *stored* in your database is not immediately relevant. The database will return (and expect) the data in whatever encoding you specify as the connection encoding. The browser will interpret the data in whatever encoding you tell it to. – deceze Feb 04 '15 at 11:56
  • @deaceze thank you, Sir for enlightening me! Sorry, i have another question... If now content is in as `latin1`, can i somehow change all table/database content as `utf8_bin`? so `ā` now would be `Ä` - and `utf-8` would read it fine? – Peter Feb 04 '15 at 12:24
  • "ā" does not become "Ä" in UTF-8. You may want to read my other article about the basics of encodings. Changing the encoding of how data is stored in the database just changes the details of the underlying bytes, it does not change the character (if you do it correctly). – deceze Feb 04 '15 at 12:41

0 Answers0