Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP \uXXXX encoded string convert to utf-8

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!

like image 740
Denis Óbukhov Avatar asked Oct 25 '11 18:10

Denis Óbukhov


1 Answers

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

like image 157
mario Avatar answered Oct 14 '22 14:10

mario