简体   繁体   中英

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

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

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; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM