PHP converts Win-1251 to UTF-8

I am extracting the contents of a Windows-1251 encoded website using file_get_html and want to serve it as UTF-8.

I set the headers in UTF-8 using: header('Content-type: text/html; charset=UTF-8');

Then I display the data using iconv("cp1252","UTF-8",'"desc":"'.$desc);

The conclusion is no longer a strange question mark, but it is still not Cyrillic.

+4
source share
2 answers

Do not try to add anything to your line, letting it just

 iconv("cp1252","UTF-8",$desc); 

By the way, you get a way out of the Cyrillic alphabet if you just do

 header('Content-Type: text/html; charset=cp1252'); echo $desc; // No iconv 
+3
source

Fixed, it turned out that this is not cp1252, but cp1251!

+2
source

All Articles