tags:

views:

48

answers:

1

Ok so I have a surrogate pair, example below:

\u306f\u30fc

Is there a function I can use to print the character to the screen?

Regards,

+2  A: 

If you want to do it manually:

echo chr(0x30) . chr(0x6f) . chr(0x30) . chr(0xfc);

If you have the string, you could always do:

$callback = function($match) { 
    return chr(hexdec($match[1])) . chr(hexdec($match[2]));
}
preg_replace_callback('#\\\\u([0-9a-f]{2})([0-9a-f]{2})#', $callback, $string);

Or, if php < 5.3

$callback = create_function('$match', 
    'return chr(hexdec($match[1])) . chr(hexdec($match[2]));'
);
preg_replace_callback('#\\\\u([0-9a-f]{2})([0-9a-f]{2})#', $callback, $string);
ircmaxell
No I don't have the string.If I wanted to post something like that to Twitter or Facebook using their API's how would I convert that to a character that can be posted?
Jamie Redmond
I initially down-voted but then I realized that this is a possible interpretation of the OP's question, that he wants a string encoded in UTF-16. Generally those escape sequences appear in the middle of ASCII text, and it's a bit more complicated to unescape them. See http://stackoverflow.com/questions/3506988/output-utf-16-a-little-stuck/3508040#3508040
Artefacto