PHP 中对汉字进行 Unicode 编码的方法:
使用 mb_convert_encoding
函数:
$str = '汉字';
$encoded = mb_convert_encoding($str, 'UTF-16', 'UTF-8');
对于解码,可以使用 mb_convert_encoding
函数:
$decoded = mb_convert_encoding($encoded, 'UTF-8', 'UTF-16');
请注意,需要在编码前先确定字符串的编码方式,然后再进行转换。