1

How to decode something beginning with "\u" with PHP

e.g.

\u4f60\u5df2\u7ecf\u6dfb\u52a0\u4e86\u6b64\u8bdd\u9898

thank you

stacker
  • 68,052
  • 28
  • 140
  • 210
meditic
  • 61
  • 1
  • 6
  • possible duplicate of http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha – Code Magician Nov 18 '11 at 10:30
  • Check this link: http://stackoverflow.com/questions/1140660/how-to-get-uxxxx-to-display-correctly-using-php5 – user1045217 Nov 18 '11 at 10:31
  • Lots of string literal formats use `\u` notation, but they all have small differences from each other. There is probably one particular parser you need to match... for example if this has come from a JSON submission, you should be reading it using a JSON parser. – bobince Nov 18 '11 at 14:16

1 Answers1

2

With PHP 5.4/intl:

$s = "\u4f60\u5df2\u7ecf\u6dfb\u52a0\u4e86\u6b64\u8bdd\u9898";
echo transliterator_transliterate("Hex-Any/Java", $s);

Output:

你已经添加了此话题

For versions before, you can adapt this answer.

Note that the answers here and here don't deal with supplementary characters (those that cannot be represented with one code unit in UTF-16).

Community
  • 1
  • 1
Artefacto
  • 96,375
  • 17
  • 202
  • 225