Tuesday, June 17, 2025
HomePHPThe Easiest Method for Converting Digits Between Languages

The Easiest Method for Converting Digits Between Languages

In this article, I’ll demonstrate how to convert digits between languages, specifically from English to Bengali and vice versa.

First, let’s declare the variables that will store the digits for each language. For example:

$bn = ['১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯', '০'];

$en = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];

Create a function that will convert the Bengali to English

public static function bn2en(string $number)
{
    return str_replace(self::$bn, self::$en, $number);
}

Another function will transform the English to Bengali digits.

public static function en2bn(string $number)
{
    return str_replace(self::$en, self::$bn, $number);
}

That’s it. Here is a complete example

class Converter
{
    public static array $bn = ['১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯', '০'];

    public static array $en = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];

    public static function bn2en(string $number): array|string
    {
        return str_replace(self::$bn, self::$en, $number);
    }

    public static function en2bn(string $number): array|string
    {
        return str_replace(self::$en, self::$bn, $number);
    }
}

 

Atiq
Atiqhttps://elearn.softscholar.com
Software Engineer with extensive experience developing modern web applications using various programming languages and frameworks. Strong background in converting legacy systems to modern architectures and contributing to SaaS platforms. Proficient in working with microservices and cloud technologies. Adept at managing teams, implementing CI/CD pipelines, and deploying SaaS platforms to optimize enterprise operations. Proven ability to lead cross-functional teams and mentor junior developers, ensuring project success and team growth.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments