gpt4 book ai didi

php - 如何在 PHP 中总结两个 Bangla (UTF-8) 数字?

转载 作者:可可西里 更新时间:2023-10-31 22:51:07 33 4
gpt4 key购买 nike

我需要对两个 utf-8 孟加拉数字求和。这是代码:

<?php 
$a = ১২; //(12)
$b = ৫; //(5)
echo $c = $a + $b; //OUTPUR 17
?>

我需要 outpur 但现在它显示 0 那么我该怎么做呢?提前感谢所有

最佳答案

你不能就这么简单,你需要先把它们转换成普通数字:

class Converter 
{
public static $bn = ["১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯", "০"];
public static $en = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];

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

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

$a = '১২'; //(12)
$b = '৫'; //(5)

$c = Converter::bn2en($a) + Converter::bn2en($b); // $c = 17
echo Converter::en2bn($c); // ১৭

感谢此处:http://bits.mdminhazulhaque.io/php/convert-number-between-banlga-and-english-in-php.html

关于php - 如何在 PHP 中总结两个 Bangla (UTF-8) 数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44258274/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com