1

I'm trying to convert the Unicode character sequence in $str into it's Bengali form. Can any one help, please?

$str = "\u0986\u09b2-\u09ac\u09bf\u09b0\u09c1\u09a8\u09c0 \u09b9\u09be\u09b8\u09aa\u09be\u09a4\u09be\u09b2 \u09b2\u09bf\u09ae\u09bf\u099f\u09c7\u09a1";

//echo mb_convert_encoding($str, "UTF-8", "ISO-8859-1")."<br />";
echo mb_convert_encoding($str, "ISO-8859-1", "utf-8")."<br />";
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Hamid
  • 11
  • 4
  • What encoding is your web page? If it is utf-8, you don't need to convert it. What do you mean by "Bengali form"? – rghome May 08 '17 at 11:39
  • @rghome: $str contains a bengali language string encoded in Unicode. i want to display str in Bengali language. – Hamid May 08 '17 at 12:00
  • Have you tried just outputing it without trying to convert it? – rghome May 08 '17 at 12:06
  • if i directly output the equivalent Bengali character glyphs are showing automatically. that's alright. but the source from which i'm getting the string is delivers data in unicode encode like in $str above. what i want is to get those character glyphs in a new variable and do some more things programatically. – Hamid May 08 '17 at 12:35
  • You will need to update your question explaining what your import source is, how the data arrives and what you want to do, as it is not clear. However, maybe this is what you want: http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha – rghome May 08 '17 at 12:43
  • yes! great! it worked. thank you for your time! – Hamid May 08 '17 at 13:00
  • ok - great! But I will have to mark the question as a duplicate. Then other people will get directed to the answer as well. – rghome May 08 '17 at 21:46
  • Possible duplicate of [How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?](http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha) – rghome May 08 '17 at 21:47

1 Answers1

0

Only for PHP 7+

From PHP version 7 or upper, Unicode codepoint escape syntax can be used to do this easily.

$str = "\u{0986}\u{09b2}-\u{09ac}\u{09bf}\u{09b0}\u{09c1}\u{09a8}\u{09c0} \u{09b9}\u{09be}\u{09b8}\u{09aa}\u{09be}\u{09a4}\u{09be}\u{09b2} \u{09b2}\u{09bf}\u{09ae}\u{09bf}\u{099f}\u{09c7}\u{09a1}";
echo $str;

The output is:

আল-বিরুনী হাসপাতাল লিমিটেড

UkFLSUI
  • 5,509
  • 6
  • 32
  • 47