将波斯/阿拉伯数字转换为英文数字 [英] convert Persian/Arabic numbers to English numbers

查看:131
本文介绍了将波斯/阿拉伯数字转换为英文数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过简单的功能将波斯/阿拉伯数字转换为英语数字?

How can I convert Persian/Arabic numbers to English numbers with a simple function ?

波斯/阿拉伯数字:

Persian/Arabic numbers:

۰   //  -> 0
۱   //  -> 1
۲   //  -> 2
۳   //  -> 3
۴   //  -> 4
۵   //  -> 5
۶   //  -> 6
۷   //  -> 7
۸   //  -> 8
۹   //  -> 9

Unicode上的数字:

numbers over the unicode :

$num0="۰";
$num1="۱";
$num2="۲";
$num3="۳";
$num4="۴";
$num5="۵";
$num6="۶";
$num7="۷";
$num8="۸";
$num9="۹";

推荐答案

由于波斯和安哥拉的人阿拉伯地区可能会使用其他语言,这是将两种类型都转换的完整解决方案.

Because of people at Persian & Arabic region maybe use each other language , this is the complete solution to convert both type .

function convert2english($string) {
    $newNumbers = range(0, 9);
    // 1. Persian HTML decimal
    $persianDecimal = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
    // 2. Arabic HTML decimal
    $arabicDecimal = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
    // 3. Arabic Numeric
    $arabic = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
    // 4. Persian Numeric
    $persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');

    $string =  str_replace($persianDecimal, $newNumbers, $string);
    $string =  str_replace($arabicDecimal, $newNumbers, $string);
    $string =  str_replace($arabic, $newNumbers, $string);
    return str_replace($persian, $newNumbers, $string);
}

这篇关于将波斯/阿拉伯数字转换为英文数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆