Convert from "Java Escape" to Index in PHP

Is there any form for converting a string in Java Escape to a unicode index in PHP?

I have this line:

$ str = "\ud83d\ude0e";

And I need to get the part after U +:

U+1F60E 

Or python code:

u'\U0001f60e'

Compliance Codes: http://www.charbase.com/1f60e-unicode-smiling-face-with-sunglasses

Thank.

==== EDIT 09/03 ====

Sorry for the delay and thank you for your reply, but I can not do what I need.

I need to replace the caracter with an image, so I:

$src = "Hello "."\ud83d\ude0e";

$replaced = preg_replace("/\\\\u([0-9A-F]{1,8})/i", "&#x$1;", $src);

$replaced = str_replace('&#x1f60e', '<img src="data/emoji_new/1F60E.png">', $replaced);

$result = mb_convert_encoding($replaced, "UTF-8", "HTML-ENTITIES");

But do not work. Result:

"Hello   "

Any idea?

Thanks again!

+5
source share
1 answer

Very similar to PHP: convert Unicode code point to UTF-8

Goes straight out of 4 char bytes if you can.

$src = "Hello \u0001f60e";

$replaced = preg_replace("/\\\\u([0-9A-F]{1,8})/i", "&#x$1;", $src);

$result = mb_convert_encoding($replaced, "UTF-8", "HTML-ENTITIES");

echo "Result is [$result] and string length is ".mb_strlen($result);

, .

Result is [Hello 😎] and string length is 10

UTF-16:

$src = "Hello "."\ud83d\ude0e";

$replaced = preg_replace("/\\\\u([0-9A-F]{1,4})/i", "&#x$1;", $src);

$result = mb_convert_encoding($replaced, "UTF-16", "HTML-ENTITIES");

$result = mb_convert_encoding($result, 'utf-8', 'utf-16');

echo "Result is [$result] and string length is ".mb_strlen($result)."\n";

$resultInHex = unpack('H*', $result);

$resultInHex = $resultInHex[1];

$resultSeparated = implode(', ', str_split($resultInHex, 2));

echo "in hex: ".$resultSeparated;

:

Result is [Hello 😎] and string length is 10
in hex: 48, 65, 6c, 6c, 6f, 20, f0, 9f, 98, 8e

, : " Java?", Java UTF-16 .

+2

All Articles