When I moved from php mysql shared hosting to my own VPS I've found that code which outputs user names in UTF8 from mysql database outputs ?�??????�
instead of 鬼神❗
. My page has utf-8
encoding, and I have default_charset = "UTF-8"
in php.ini, and header('Content-Type: text/html; charset=utf-8');
in my php file, as well as <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in html part of it.
My database has collation utf8_bin, and table has the same. On both previos and current hosting in phpmyadmin for this database record I see: 鬼神❗
. When I create ANSI text file in Notepad++, paste 鬼神❗
into it and select Encoding->Encode in UTF-8 menu I see 鬼神❗
, so I suppose it is correct encoded UTF-8 string.
Ok, and then I added
init_connect='SET collation_connection = utf8_general_bin'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_bin
skip-character-set-client-handshake
to my.cnf and now my page shows 鬼神❗
instead of ?�??????�
. This is the same output I get in phpmyadmin on both hostings, so I'm on a right way. And still somehow on my old hosting the same php script returns utf-8 web page with name 鬼神❗
while on new hosting - 鬼神❗
. It looks like the string is twice utf-8 encoded: I get utf-8 string, I give it as ansi string to Notepad++ and it encodes it in correct utf-8 string.
However when I try utf8_encode()
I get й¬ÑзÒÑвÑâ
, and utf8_decode()
returns ?�???????
. The same result return mb_convert_encoding($name,"UTF-8","ISO-8859-1");
and iconv( "ISO-8859-1","UTF-8", $name);
.
So how could I reproduce the same conversion Notepad++ does? See answer below.