2013-02-28 8 views
5

Java Escapeの文字列をPHPのIndex Unicodeに変換するフォームはありますか?PHPの "Java Escape"からインデックスへの変換

私は、この文字列を持っている:

$ str = "\ud83d\ude0e"; 

をそして私はU +の後の部分を取得する必要があります。

U+1F60E 

やPythonのコード:

u'\U0001f60e' 

対応コード:http://www.charbase.com/1f60e-unicode-smiling-face-with-sunglasses

ありがとうございました。

私の遅れて申し訳ありません==== EDIT 09/03 ====

とお返事をありがとうございましたが、私は必要なものを行うことが - 私はできません。

私はイメージでcaracterを交換する必要があるので、私は実行します。

$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"); 

しかし、動作しない...結果は次のとおりです。

"Hello ��" 

どれよりのアイデア?

もう一度ありがとうございます!できればPHP: Convert unicode codepoint to UTF-8

は4バイトの文字からまっすぐ行くと非常に似て

答えて

2

$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 

または2 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; 

出力: '?Javaのエスケープとは何である' 疑問に思っているすべての人のために

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

、Javaは、全ての文字をエンコードします内部的にはUTF-16です。