Answers for "convert Persian/Arabic numbers to English numbers PHP"

PHP
0

convert Persian/Arabic numbers to English numbers PHP

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);
}
Posted by: Guest on April-28-2022

Code answers related to "convert Persian/Arabic numbers to English numbers PHP"

Browse Popular Code Answers by Language