在 PHP 中,可以使用 mb_convert_encoding() 函数进行中文和 Unicode 之间的互转。
要将中文转换为 Unicode,可以使用以下代码:
$chinese = "中文";$unicode = mb_convert_encoding($chinese, 'unicode');echo $unicode; // 输出:\u4e2d\u6587要将 Unicode 转换为中文,可以使用以下代码:
$unicode = '\u4e2d\u6587';$chinese = mb_convert_encoding($unicode, 'utf-8', 'unicode');echo $chinese; // 输出:中文注意,mb_convert_encoding() 函数的第一个参数是要转换的字符串,第二个参数是目标编码,第三个参数是原始编码。在上面的示例中,目标编码为 UTF-8,原始编码为 Unicode。

