R0b0tn1k
R0b0tn1k

Reputation: 4306

PHP convert Win-1251 to UTF-8

I'm fetching the contents of a Windows-1251 encoded web site using file_get_html and want to serve it as UTF-8.

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

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

The output is no longer strange questions marks, but it's still not Cyrillic.

Upvotes: 4

Views: 10139

Answers (2)

R0b0tn1k
R0b0tn1k

Reputation: 4306

Fixed it, turns out it wasn't cp1252, but cp1251!

Upvotes: 2

ssice
ssice

Reputation: 3683

Try not prepending anything to your string, letting it be just

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

By the way, do you get the cyrillic output if you just do

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

Upvotes: 3

Related Questions