如何在 PHP 中将 utf-8 字符串转换为 utf-16 字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/155514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:42:12  来源:igfitidea点击:

How to convert a utf-8 string to a utf-16 string in PHP

phputf-8utf-16

提问by Freddo411

How do I convert a utf-8 string to a utf-16 string in PHP?

如何在 PHP 中将 utf-8 字符串转换为 utf-16 字符串?

回答by chroder

mbstring supports UTF-16, so you can use mb_convert_encoding.

mbstring支持 UTF-16,因此您可以使用mb_convert_encoding.

回答by Jesper Grann Laursen

You could also use iconv.

您也可以使用iconv.

It's native in PHP, but require that all your text is one charset. Else it could discard characters.

它是 PHP 原生的,但要求所有文本都是一个字符集。否则它可能会丢弃字符。