unicode转utf8函数
2019-11-15 dingshangchao php开发
1. function unicode2utf8($str) { $str = '{"result_str":"' . $str . '"}'; $strarray = json_decode ( $str, true ); return $test = $strarray ['result_str']; }
2.
function unicode_to_utf8($unicode_str) {
$code = intval(hexdec($unicode_str));
//这里注意转换出来的code一定得是整形,这样才会正确的按位操作
$ord_1 = decbin(0xe0 | ($code >> 12));
$ord_2 = decbin(0x80 | (($code >> 6) & 0x3f));
$ord_3 = decbin(0x80 | ($code & 0x3f));
$utf8_str = chr(bindec($ord_1)) . chr(bindec($ord_2)) . chr(bindec($ord_3));
return $utf8_str;
}
标签: php