PHP to implement the conversion of code, here will convert gb2312 into Utf-8
function Gb2utf8 ($GB) {
if (!trim ($GB)) return $GB;
$utf 8 = ';
while ($GB) {
if (Ord (substr ($GB, 0,1)) > 127) {
$t =substr ($GB, 0,2);
$GB =substr ($GB, 2);
$utf 8. = $this->u2utf8 ($this->codetable[hexdec (Bin2Hex ($t)) -0x8080]);
}
else {
$t =substr ($GB, 0, 1);
$GB =substr ($GB, 1);
$utf 8. = $this->u2utf8 ($t);
}
}
return $UTF 8;
}
function U2utf8 ($c) {
$str = ';
if ($c < 0x80) {
$str. = $c;
}
else if ($c < 0x800) {
$str. =CHR (0xc0 | $c >>6);
$str. =CHR (0x80 | $c & 0x3F);
}
else if ($c < 0x10000) {
$str. =CHR (0xe0 | $c >>12);
$str. =CHR (0x80 | $c >>6 & 0x3F);
$str. =CHR (0x80 | $c & 0x3F);
}
else if ($c < 0x200000) {
$str. =CHR (0xF0 | $c >>18);
$str. =CHR (0x80 | $c >>12 & 0x3F);
$str. =CHR (0x80 | $c >>6 & 0x3F);
$str. =CHR (0x80 | $c & 0x3F);
}
return $str;
}
To say a little, the code set I do not write out, with a for a moment to know.