Convert numbers from English to Bangla

Today Ayon came up  with a problem that he needs to convert English digits to Bangla. The Input would be something like “1 ডলার = 81.55 টাকা” and the output should be “১ ডলার = ৮১.৫৫ টাকা”. How to do it?

Its very easy to do. In fact most developers will be able to do it within few minutes. I just want to share my solution.

I use PHP’s str_replace function.

 $bn_digits=array('০','১','২','৩','৪','৫','৬','৭','৮','৯');
$output = str_replace(range(0, 9),$bn_digits, $input); 

Thats it. You can wrap it with a function and re use it.


Author: shiplu

The Lone Explorer.

14 thoughts on “Convert numbers from English to Bangla”

    1. bangla to english and english to bangla with same method in c#:
      private string SwitchEngBan(string number)
      {
      string en = “1234567890.,”;
      string bn = “১২৩৪৫৬৭৮৯০.,”;
      return number.Select(o => en.Contains(o)
      ? bn.Substring(en.IndexOf(o), 1)
      : en.Substring(bn.IndexOf(o), 1))
      .Aggregate((a, b) => a + b);
      }

  1. Dear,
    Your post is very useful. But I am a noob in developing PHP.
    If I want to use it in WordPress theme, where I need to put the code?
    Can you suggest me? I would love that. Very thankful to you.

    1. Its much simpler in JS too.


      var bn_digits = ["০", "১", "২", "৩", "৪", ....]
      function tr_digits(s){
      return s.replace(/\d/, function(a){
      return bn_digits[a]
      })
      }

      Then you just call tr_digits(“312 taka”).

    1. I don’t get you. If you are asking about how to do it my MySQL, my answer is “Replace the number with this function then pass it to mysql query”

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve * Time limit is exhausted. Please reload the CAPTCHA.