如何在PHP中将UTF-16十六进制字符串转换为UTF-8? [英] How to Convert UTF-16 hexadecimal string to UTF-8 in PHP?

查看:276
本文介绍了如何在PHP中将UTF-16十六进制字符串转换为UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从strace获得以下输出,我想使用PHP将其转换为UTF-8:

I have the following output from strace and i want to convert it to UTF-8 using PHP:

R\00f6dhakev\00e4gen 4
R\00e4ntm\00e4starv\00e4gen 24
K\00d8BENHAVN

我认为上述字符串是UTF 16十六进制.

The above strings is UTF 16 HEX i think.

推荐答案

发现以下功能有效:

function utf8_urldecode($str) {

  $str = str_replace("\\00", "%u00", $str);

  $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));

  return html_entity_decode($str,null,'UTF-8');

}

来自 http://us2.php.net/manual/zh-CN的某些部分/function.urldecode.php

这篇关于如何在PHP中将UTF-16十六进制字符串转换为UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆