输出UTF-16?有点卡住了
我有一些代理对形式的 UTF-16 编码字符。我想将这些代理对作为字符输出在屏幕上。
有谁知道这怎么可能?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有一些代理对形式的 UTF-16 编码字符。我想将这些代理对作为字符输出在屏幕上。
有谁知道这怎么可能?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
iconv('UTF-16', 'UTF-8', yourString)
iconv('UTF-16', 'UTF-8', yourString)
你的问题有点不清楚。
如果您有嵌入 UTF-16 转义序列的 ASCII 文本,则可以通过以下方式将所有内容转换为 UTF-8:
这给出了 UTF-8 中的字符
Your question is a little unclear.
If you have ASCII text with embedded UTF-16 escape sequences, you can convert everything to UTF-8 in this way:
which gives the character ???? in UTF-8 (requires 4 bytes since it's outside the BMP).
If all your text is UTF-16 (including HTML tags, etc.), you could simply tell the browser the output is in UTF-16:
This is very rare, because PHP scripts cannot be written in UTF-16 (unless PHP is compiled with multibyte support), which would make printing literal strings awkward.
So you probably only have a piece of text in UTF-16 that you want to convert to whatever encoding your webpage is using. You can do this conversion with: