I have string like this:
Óâàæàåìûé êëèåíò!
And want to decode it into cyrillic symbols. I'm already try to decode by mb_convert_encoding, but don't get the proper result.
$string = 'Óâàæàåìûé êëèåíò!';
$stringEncode = mb_detect_encoding($string);
$result = mb_convert_encoding($string, "CP1251", $stringEncode);
echo $result //????????? ??????!
//Case with auto detect encoding return the same result
$result = mb_convert_encoding($string, "CP1251");
echo $result //????????? ??????!
I'm try to use different Character Encodings but always get wrong result.
Proper result must be:
Уважаемый клиент!
Notice! I'm try to use online services for encoding current string and get the proper result. The string is not broken. It seems like PHP can't to define encoding and convert current string into cyrillic.
Thnx for any help!
UPD:
bin2hex output: c393c3a2c3a0c3a6c3a0c3a5c3acc3bbc3a920c3aac3abc3a8c3a5c3adc3b22120c387c3a0c3a2c3b2c3b0c3a020c3adc3a5c3aec3a1c3b5c3aec3a4c3a8c3acc3ae20c3a2c3adc3a5c3b1c3b2c3a820c3acc3a8c3adc3a8c3acc3a0c3abc3bcc3adc3bbc3a920c3afc3abc3a0c3b2c3a5c3a620c3afc3ae20c3a7c3a0c3a9c3acc3b320c3a220c3b0c3a0c3a7c3acc3a5c3b0c3a52036343120c3b0c3b3c3a1c3abc3a5c3a92e20c384c3abc3bf20c3aec3afc3abc3a0c3b2c3bb20c3a2c3aec3b1c3afc3aec3abc3bcc3a7c3b3c3a9c3b2c3a5c3b1c3bc20c3abc3a8c3b7c3adc3bbc3ac20c3aac3a0c3a1c3a8c3adc3a5c3b2c3aec3ac20707572652e636f6d2e7275
"Where does that string come from originally?" - originally I get the response from Api in json format, then I use utf8_encode (if I don`t use this function json_decode return null) and finally json_decode return me an array of data:
[
'status' => '1',
'last_date' => '15.05.2018 10:00:17',
'last_timestamp' => '1526353217',
'send_date' => '15.05.2018 10:00:05',
'send_timestamp' => '1526353205',
'phone' => '79270212817',
'cost' => '6.24',
'sender_id' => 'PURE',
'status_name' => 'Äîñòàâëåíî',
'message' => 'Óâàæàåìûé êëèåíò!'
];
According to deceze advice, I get encoding for my origin Api response (windows-1251). Than I rewrite my 'prepare to json_decode' code and get the proper result.
//Replace this:
$contents = utf8_encode($response);
//To this:
$contents = mb_convert_encoding($response, 'utf-8', 'windows-1251');
$result = json_decode($contents);
Notice! That utf8_encode convert ISO-8859-1 to UTF-8 and if we pass data with another encoding (in my case it windows-1251) into this function, we will receive unsuspected result. Big thnx to @mulquin and @deceze to helped me find out this problem.
PS: Always check the encoding of the source data, don't repeat my mistakes :)