How to convert between utf8 and cp-1251 without iconv or mbstring
8th July 2007
This helped me, maybe it will help you: How to convert between utf8 and cp1251 without iconv
In case the original disappears, here's a "backup":
PHP:
-
function cp1251_to_utf8($s){
-
for($i=0; $i<strlen($s); $i++) {
-
elseif ($c==184) $t.=$c209.$c209;
-
elseif ($c==168) $t.=$c208.$c129;
-
else $t.=$s[$i];
-
}
-
return $t;
-
}
-
-
function utf8_to_cp1251($s)
-
{
-
for ($c=0;$c<strlen($s);$c++)
-
{
-
if ($i<=127) $out.=$s[$c];
-
if ($byte2){
-
$new_c2=($c1&3)*64+($i&63);
-
$new_c1=($c1>>2)&5;
-
$new_i=$new_c1*256+$new_c2;
-
if ($new_i==1025){
-
$out_i=168;
-
} else {
-
if ($new_i==1105){
-
$out_i=184;
-
} else {
-
$out_i=$new_i-848;
-
}
-
}
-
$byte2=false;
-
}
-
if (($i>>5)==6) {
-
$c1=$i;
-
$byte2=true;
-
}
-
}
-
return $out;
-
}