0

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

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • possible duplicate of [Unicode character in PHP string](http://stackoverflow.com/questions/6058394/unicode-character-in-php-string) – Kristiyan Aug 18 '15 at 13:25

1 Answers1

0

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; 
deceze
  • 510,633
  • 85
  • 743
  • 889
Hearner
  • 2,711
  • 3
  • 17
  • 34
  • Hi Hearner , Thanks a lot its working. one more request. if i want to make it as "U+0041" for "A" what changes can be done in this any help can be appreciated... – Siddeshwar Vanga Aug 18 '15 at 13:27
  • Its not working for multiple characters ... :) Thanks a lot for your efforts :) – Siddeshwar Vanga Aug 18 '15 at 13:48
  • You want, for example, "AB" to be `U+0041 U+0042` ? – Hearner Aug 18 '15 at 13:49
  • 1
    No , Actually I want continuous string like .. 00410042 like this .. so i , utilized the function you have given me with that .. i have divided that string by 8 characters each to make it array using "str_split" then using for loop made that long string. Thanks a lot Hearner.. your answer was very helpful to me. – Siddeshwar Vanga Aug 19 '15 at 12:49
  • No problem, I tried to make the simplest code I could :) If you need anything you can ask. – Hearner Aug 19 '15 at 12:52