Created
November 3, 2012 22:15
-
-
Save baghayi-gist/4009084 to your computer and use it in GitHub Desktop.
PHP: Converting Persian Numbers To English One (function).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertPersianNumbersToEnglish($number) | |
{ | |
$persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'); | |
$num = range(0, 9); | |
return (int)str_replace($persian, $num, $number); | |
} |
fun replacePersianAndArabic(txt: String): String {
return txt.replace("۰", "0")
.replace("۱", "1")
.replace("۲", "2")
.replace("۳", "3")
.replace("۴", "4")
.replace("۵", "5")
.replace("۶", "6")
.replace("۷", "7")
.replace("۸", "8")
.replace("۹", "9")
.replace("٩", "9")
.replace("٨", "8")
.replace("٧", "7")
.replace("٦", "6")
.replace("٥", "5")
.replace("٤", "4")
.replace("٣", "3")
.replace("٢", "2")
.replace("١", "1")
.replace("٠", "0")
}
same work in kotlin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
private function conToEn($string) {
$range = range(0, 9);
// Persian
$persianDecimal = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
// Arabic
$arabicDecimal = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
// number Arabic
$arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
// number Persian
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
}