将 unicode 转换为字符

Convert a unicode to characters

我尝试在 vBulletin 论坛中构建标记系统,它工作正常。

但是我对 post 的快速编辑有问题(使用 AJAX)。

如果我写的字符是希伯来语,它会将字符替换为 Unicode。

当我用希伯来语写 post 时的一个例子:

חחחחח לא?test!!

会变成这样:

%u05D7%u05D7%u05D7%u05D7%u05D7 %u05DC%u05D0?test!!

看起来好像是已弃用的 javascipt 函数 escape() is being used to encode the string. If you're echoing this out in the webpage via JavaScript, you could use unescape() - see this fiddle。然而,如上所述,这已被弃用。

应该使用 encodeURIComponent() in place of escape(), and decodeURIComponent() in place of unescape(). Then, you can use urldecode() 在 PHP 中的函数以获得您想要的结果,如果这是必要的步骤。


根据您当前的设置,要将 unicode 字符转换为 html 适合在浏览器中呈现的实体,以下操作应该符合您的要求:

$str = preg_replace_callback('/%u([0-9a-fA-F]{4})/', function ($match) {
    return mb_convert_encoding(pack('H*', $match[1]), 'HTML-ENTITIES', 'UCS-2BE');
}, $str);