PHP \\uXXXX encoded string convert to utf-8

2019-04-10 05:26发布

问题:

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!

回答1:

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.)



回答2:

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