-1

I am trying to get the Devnagari Unicode of a given string.

https://codepoints.net/U+0924

I have string = ""

How do I get its Unicode value (\u0924)?

I would like to get it in php or javascript.

Update

Also, string = "tkfO{". This should return \u0924\u092A\u093E\u0908.

  1. https://codepoints.net/U+0924
  2. https://codepoints.net/U+092A
  3. https://codepoints.net/U+093E
  4. https://codepoints.net/U+0908
Adarsh Khatri
  • 358
  • 1
  • 5
  • 23

2 Answers2

1

Here's a way in PHP:

function encodeString($str)
{
    $s = iconv('UTF-8', 'UTF-32BE', $str);
    $nb = strlen($s) / 4;
    $res = '';
    for($i=0;$i<$nb;$i++)
        $res .= encodeChar(substr($s, 4*$i, 4));
    return $res;
}

function encodeChar($c)
{
    $s = bin2hex($c);
    while(substr($s,0,2)=='00')
        $s = substr($s, 2);
    return '\\u'.$s;
}

echo encodeString('तपाई');

Output: \u0924\u092a\u093e\u0908

Olivier
  • 13,283
  • 1
  • 8
  • 24
1

use mb_ord and than dechex

print dechex(mb_ord("त"));
Ronak Dhoot
  • 2,322
  • 1
  • 12
  • 19