English To Arabic Number Converter

Some of the middle east project which is Arabic Site our clients want Arabic Numbers Like “٩٢٠٠١٥٠١٠” which is “920015010”. Even though it’s not Arabic number but they want to use it in their sites. So in our web projects we need to convert English “920015010” to Arabic “٩٢٠٠١٥٠١٠”.

I couldn’t find good solution for that. So I made my own class

<?php
class English2ArabicNumber {

	function English2ArabicNumber()
	{

	}

	function convert($digit)
	{
		if(empty($digit))
			return '٠';

		$ar_digit = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩','-'=>'','.'=>'.');

		$arabic_digit = '';

		$length = strlen($digit);

		for($i=0;$i<$length;$i++)
		{

			if(isset($ar_digit[$digit[$i]]))

				$arabic_digit .= $ar_digit[$digit[$i]];

		}
		return $arabic_digit;
	}
}

$ekram = new English2ArabicNumber();
echo $ekram->convert('12345');
?>

OUTPUT:

١٢٣٤٥

you can download the class from phpclass.org site

[Download]

1 thought on “English To Arabic Number Converter

Leave a Reply

Your email address will not be published. Required fields are marked *