2013-04-19 2 views
2

En C++, il est possible de créer une chaîne UTF-8 en utilisant ce type de notation: "\uD840\uDC50".Création d'une chaîne UTF-8 à partir d'un code hexadécimal

Cependant, cela ne fonctionne pas en PHP. Y a-t-il une notation similaire? Si ce n'est pas le cas, existe-t-il un moyen intégré de créer une chaîne UTF-8 connaissant son point de code Unicode?

+1

http://www.php.net/manual/en/function.chr.php#88611 – Passerby

Répondre

7

J'ai fini par mettre en œuvre comme ceci:

$utf8 = html_entity_decode("一", ENT_COMPAT, 'UTF-8'); 
+0

utilisation ENT_QUOTES | ENT_COMPAT pour convertir des citations aussi –

2
function hexToString($str){return chr(hexdec(substr($str, 2)));} 
$result = preg_replace_callback("/(\\\\x..)/isU", function($m) { return hexToString($m[0]); }, $str); 
Questions connexes