PHP Tutorial customizing UTF8 and cp1251 functions
When you need to convert some data from UTF8, cp1251 (Windows-1251) or cp1251 to UTF8 you must use the iconv of the system functions. Common hosting providers do not allow this feature to be used.
*/
function Cp1251_to_utf8 ($s) {
$c 209 = chr (209); $c 208 = chr (208); $c 129 = Chr (129);
for ($i =0; $i
$c =ord ($s [$i]);
if ($c >=192 and $c <=239) $t. = $c 208.CHR ($c-48);
ElseIf ($c >239) $t. = $c 209.CHR ($c-112);
ElseIf ($c ==184) $t. = $c 209. $c 209;
ElseIf ($c ==168) $t. = $c 208. $c 129;
else $t. = $s [$i];
}
return $t;
}
function utf8_to_cp1251 ($s)
{
for ($c =0; $c<>
{
$i =ord ($s [$c]);
if ($i <=127) $out. = $s [$c];
if ($byte 2) {
$new _c2= ($c 1&3) *64+ ($i &63);
$new _c1= ($c 1>>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;
}
}
$out. =CHR ($out _i);
$byte 2=false;
}
if (($i >>5) ==6) {
$c 1= $i;
$byte 2=true;
}
}
return $out;
}
http://www.bkjia.com/PHPjc/632361.html www.bkjia.com true http://www.bkjia.com/PHPjc/632361.html techarticle PHP Tutorial Custom UTF8 and cp1251 functions when you need to convert some data from UTF8, cp1251 (Windows-1251) or cp1251 to UTF8 you must use the system functions of iconv. Common host provider forbid ...