浏览文章
文章信息
数据库保存utf-16|emoji表情|utf-16转化普通uff-8保存
12798
1、转化json_encode
$content = json_encode($content);
2、转换编码
function utf16_to_entities(){ $content = mb_convert_encoding($content, 'utf-16'); $bin = bin2hex($content); $arr = str_split($bin, 4); $l = count($arr); $str = ''; for ($n = 0; $n < $l; $n++) { if (isset($arr[$n + 1]) && ('0x' . $arr[$n] >= 0xd800 && '0x' . $arr[$n] <= 0xdbff && '0x' . $arr[$n + 1] >= 0xdc00 && '0x' . $arr[$n + 1] <= 0xdfff)) { $H = '0x' . $arr[$n]; $L = '0x' . $arr[$n + 1]; $code = ($H - 0xD800) * 0x400 + 0x10000 + $L - 0xDC00; $str.= '&#' . $code . ';'; $n++; } else { $str.=mb_convert_encoding(hex2bin($arr[$n]),'utf-8','utf-16'); } } return $str; }