Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

numbers over the unicode :

$num0="۰";
$num1="۱";
$num2="۲";
$num3="۳";
$num4="۴";
$num5="۵";
$num6="۶";
$num7="۷";
$num8="۸";
$num9="۹";
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Here's a short function:

function convert($string) {
    $persian = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?'];
    $arabic = ['?', '?', '?', '?', '?', '?', '?', '?', '?','?'];

    $num = range(0, 9);
    $convertedPersianNums = str_replace($persian, $num, $string);
    $englishNumbersOnly = str_replace($arabic, $num, $convertedPersianNums);

    return $englishNumbersOnly;
}

You can use the unicode instead of the characters in $persian (I think).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...