当前位置 : 主页 > 网络编程 > PHP >

php utf8ToGBK

来源:互联网 收集:自由互联 发布时间:2021-06-28
utf8ToGBK function utf8ToGBK($c) { $str = ''; if ($c 0x80) { $str .= $c; } elseif ($c 0x800) { $str .= chr(0xC0 | $c 6); $str .= chr(0x80 | $c 0x3F); } elseif ($c 0x10000) { $str .= chr(0xE0 | $c 12); $str .= chr(0x80 | $c 6 0x3F); $str .=
utf8ToGBK
function utf8ToGBK($c) {
        $str = '';
        if ($c < 0x80) {
            $str .= $c;
        } elseif ($c < 0x800) {
            $str .= chr(0xC0 | $c >> 6);
            $str .= chr(0x80 | $c & 0x3F);
        } elseif ($c < 0x10000) {
            $str .= chr(0xE0 | $c >> 12);
            $str .= chr(0x80 | $c >> 6 & 0x3F);
            $str .= chr(0x80 | $c & 0x3F);
        } elseif ($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 iconv('UTF-8', 'GB2312', $str);
    }
上一篇:PHP导出Excel
下一篇:php的缓动算法
网友评论