如何解码像“u00ed"这样的 Unicode 转义序列正确的 UTF-8 编码字符? [英] How to decode Unicode escape sequences like "u00ed" to proper UTF-8 encoded characters?
本文介绍了如何解码像“u00ed"这样的 Unicode 转义序列正确的 UTF-8 编码字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PHP 中是否有一个函数可以将 Unicode 转义序列(如u00ed
")解码为í
"以及所有其他类似事件?
Is there a function in PHP that can decode Unicode escape sequences like "u00ed
" to "í
" and all other similar occurrences?
我在这里找到了类似的问题 但似乎不起作用.
I found similar question here but is doesn't seem to work.
推荐答案
试试这个:
$str = preg_replace_callback('/\\u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, $str);
如果是基于 UTF-16 的 C/C++/Java/Json 风格:
In case it's UTF-16 based C/C++/Java/Json-style:
$str = preg_replace_callback('/\\u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UTF-16BE');
}, $str);
这篇关于如何解码像“u00ed"这样的 Unicode 转义序列正确的 UTF-8 编码字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文