V
V
Vasiliy_M2018-01-19 09:22:51
PHP
Vasiliy_M, 2018-01-19 09:22:51

How to convert CP1252 to UTF-8 in PHP?

Faced a problem. On sockets I receive a miracle line. At the PHP level, I can't recode it!

<?php
$str = 'Çíà÷åíèå ADDRESS[0][48] íå íàéäåíî';

// mb_detect_encoding покажет UTF-8, но на деле строка в CP1252
echo mb_detect_encoding($str) . PHP_EOL;

// Пытаемся преобразовать хоть в какую кодировку:
echo mb_convert_encoding($str, 'CP1251') . PHP_EOL;
echo mb_convert_encoding($str, 'ASCII') . PHP_EOL;
echo mb_convert_encoding($str, 'UTF-8') . PHP_EOL;
// и прочие варианты тоже не работают

The Lebedev decoder successfully decodes this string into cp1251 and says that this is actually a string in cp1252.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Tallmange, 2018-01-19
@Vasiliy_M

$str = 'Çíà÷åíèå ADDRESS[0][48] íå íàéäåíî';
$str = iconv('utf-8', 'cp1252', $str);
echo iconv('cp1251', 'utf-8', $str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question