Rella
Rella

Reputation: 66945

How to transcode Windows-1251 to UTF-8?

How to transcode Windows-1251 to UTF-8?

Will such function do it?

function win_to_utf($s) 
{ 
for($i=0, $m=strlen($s); $i<$m; $i++) 
{ 
$c=ord($s[$i]); 
if ($c<=127) 
{$t.=chr($c); continue; } 
if ($c>=192 && $c<=207) 
{$t.=chr(208).chr($c-48); continue; } 
if ($c>=208 && $c<=239) 
{$t.=chr(208).chr($c-48); continue; } 
if ($c>=240 && $c<=255) 
{$t.=chr(209).chr($c-112); continue; } 
if ($c==184) { $t.=chr(209).chr(209); 
continue; }; 
if ($c==168) { $t.=chr(208).chr(129); 
continue; }; 
} 
return $t; 
} 

Upvotes: 1

Views: 4309

Answers (2)

ZZ Coder
ZZ Coder

Reputation: 75456

Your conversion doesn't look correct. Why don't you use iconv or mbstring?

$utf8 = iconv('windows-1251', 'utf-8', $ansi);

Upvotes: 3

Johan
Johan

Reputation: 5053

Php.net has a couple of helpful examples.

Upvotes: 1

Related Questions