I
I
Ilya2018-05-14 02:06:41
PHP
Ilya, 2018-05-14 02:06:41

How to convert text from Windows-1252 encoding to UTF-8?

Does not work:

$metro = 'Ìåòðî Ïëàíåðíàÿ 474 ì';
$metro = iconv('CP1252', 'UTF-8', $metro);

So too:
$metro = 'Ìåòðî Ïëàíåðíàÿ 474 ì';
$metro = iconv('CP1252', 'CP1251', $metro);
$metro = iconv('CP1251', 'UTF-8', $metro);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2018-05-14
@sidorchik

you are making the same mistake as in previous parsing questions: working with already interpreted data instead of raw data.
when you write a line in a file, it acquires the encoding of this file, and not the original one, respectively, any conversion rituals are meaningless. $metro = 'Ìåòðî Ïëàíåðíàÿ 474 ì';

P
profesor08, 2018-05-14
@profesor08

Save all your files in UTF-8 encoding. Specify UTF-8 encoding for the document. After these steps, you can start playing around with encoding conversion. mb_detect_encoding will help you find out what encoding the resulting text is in, in case something went wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question