Unicode Numeric figure converstion

Now a day, many open source packages are translating in Bangla. This is usually done by replacing the language file with equivalent Bangla language’s Unicode value. But problem is that the numeric figures are still in English. I faced this problem in Projanmo Forum. So today I make a script to convert these English numeric figures to Bangla.

function convert($char){

switch($char){
case "1":
return "১";
break;
case "2":
return "২";
break;
case "3":
return "৩";
break;
case "4":
return "৪";
break;
case "5":
return "৫";
break;
case "6":
return "৬";
break;
case "7":
return "৭";
break;
case "8":
return "৮";
break;
case "9":
return "৯";
break;
case "0":
return "০";
break;
default:
return $char;
break;

}
}

function unicode($str){
$count=strlen($str);
$uni='';
for($i=0;$i<$count;$i++){
if(is_int($i)){
$uni.=convert(substr($str,$i,1));
}
}

return $uni;
}

?>

After putting this code in a file, you have to include with any existing php file from where you wanna call this function.

Suppose there is a code in your forum or any other script:

echo $num;
?>

which produces 100 for example.

Now use

echo unicode($num);
?>

So, this will show 100 in Bengali (Bangla).

Thats it :).

Update (06/12/2007):
Version 2x is now available. Now Day Name (Sun, Mon etc.) and Month Name (Jan, Feb etc.) will also be Converted to Bangla.
Download the attachment for the full script.

  • ভাল
    ভাল লিখছেন ….
    সুন্দর লিখছেন…..

  • Wow….. That’s Gra8.

    Wow….. That’s Gra8.

  • ahhh… very easy one… i
    ahhh… very easy one… i lyk this one… great job! 🙂

  • Rajib Rahman

    that’s really cool
    that’s really cool script….and very useful also…
    i am really enjoying it…thanks a lot hungrycoder(Raju bahi)
    for your post….

  • hungrycoder

    problem is that browser is
    problem is that browser is showing the ১ ২ ৩ ৪ ৫ ৬ ৭ ৮ ৯ ০ instead of their unicode entity in the above code. you have to put unicode value instead of real bangla characters or you can save your document as unicode.

  • Can I use this in SMF or is
    Can I use this in SMF or is it created only for Punbb?

  • hungrycoder

    yes, you can use it in SMF
    yes, you can use it in SMF too. this could be used anywhere.

    you just bind a variable by this function. for example.

    if the code is:
    < ?php echo $num_posts; ?>

    you simply make it:
    < ?php echo unicode($num_posts); ?>

    thats it.

    thanks

  • very easy one

  • এটা ওয়ার্ডপ্রেসে কিভাবে ব্যবহার করবো?
    ওয়ার্ডপ্রেসের সব ইংরেজী সংখ্যা বাংলায় দেখাতে এটা কি কাজ করবে ?

  • admin

    @Mukul,
    You may write a plugin that will do what you want!

  • rony

    জুমলায় কিভাবে ব্যবহার করব? জানালে খুবই উপকার হবে।