convert any string or a character in php to unicode code points

人走茶凉 提交于 2020-08-06 05:12:19

问题


How to convert any string or a character in php to "unicode code points"

for example : unicode code points of letter अ is 0905

and A is 0041

I need a continuous string if i pass Aअ which will give me a output as 00410905


回答1:


Use this function

function Unicode_decode($text) {
     return implode(unpack('H*', iconv("UTF-8", "UCS-4BE", $text)));
 }

If you want to have U+0000 use this :

for ($i=0; $i < strlen($word); $i++)
{
    $wordConvert = Unicode_decode($word[$i]);
    $result .= "U+" . substr($wordConvert, -4, 4) . "<br/>";

}

echo $result; 


来源:https://stackoverflow.com/questions/32073179/convert-any-string-or-a-character-in-php-to-unicode-code-points

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