Converting Unicode character to text in PHP is not working

只谈情不闲聊 提交于 2020-01-07 03:08:20

问题


I am trying to convert Unicode character to text in PHP. But the string is the mixture of Unicode characters and text. But it is not working.

I followed this link (Unicode character in PHP string)

<?php

   $unicodeChar = "{'singer': u'', 'name': u'\\\\u101c\\\\u1031\\\\u1011\\\\u1032\\\\u101c\\\\u103d\\\\u103e\\\\u1004\\\\u1037\\\\u103a\\\\u101c\\\\u102d\\\\u102f\\\\u1000\\\\u103a'}\\r\\n\\r\\n    artist          : Thar Gyi\\r\\n    album           : Sal Pone Ta Pone\\r\\n    genre           : R&B\\r\\n    copyright       : MyanmarSongs.NET\\r\\n    track           : 1\\r\\n    title           : Lay Htal Hlwint Lite";
   echo json_decode('"'.$unicodeChar.'"');
   echo mb_convert_encoding($unicodeChar, 'UTF-8', 'HTML-ENTITIES'); 
   echo mb_convert_encoding($unicodeChar, 'UTF-8', 'UTF-16BE'); showing nothing

?>

All the above scenarios are not working when the value is the mixtures of Unicode characters and text like I used. But it is working when the value is so simple like this:

$unicodeChar = '\u1000';
echo json_decode('"'.$unicodeChar.'"');

How can I achieve this?


回答1:


use following code

$unicodeChar = '\u1000';
echo json_decode('"'.$unicodeChar.'"');


来源:https://stackoverflow.com/questions/34018194/converting-unicode-character-to-text-in-php-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!