PHP \uXXXX encoded string convert to utf-8

2019-04-10 05:16发布

I've got such strings

\u041d\u0418\u041a\u041e\u041b\u0410\u0415\u0412

How can I convert this to utf-8 encoding? And what is the encoding of given string? Thank you for participating!

2条回答
Bombasti
2楼-- · 2019-04-10 05:46

The simple approach would be to wrap your string into double quotes and let json_decode convert the \u0000 escapes. (Which happen to be Javascript string syntax.)

 $str = json_decode("\"$str\"");

Seems to be russian letters: НИКОЛАЕВ (It's already UTF-8 when json_decode returns it.)

查看更多
走好不送
3楼-- · 2019-04-10 05:55

To parse that string in PHP you can use json_decode because JSON supports that unicode literal format.

查看更多
登录 后发表回答