technico
technico

Reputation: 113

symfony 2 how to make numbers appear in western arabic

i am making an arabic website with symfony2 ! when i set the locale as "ar" for arabic, even numbers are converted in arabic !

Western Arabic 0 1 2 3 4 5 6 7 8 9 became: Eastern Arabic ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩

is there a solution to make the numbers appears in the wester form ?

thank you !

Upvotes: 2

Views: 469

Answers (3)

Aref Ben Lazrek
Aref Ben Lazrek

Reputation: 1064

It's an old question but if someone is facing this problem You must change the locale from ar to another arab country which doesn't use eastern numbers for eg Tunisia

locale: ar_TN

Upvotes: 1

Ramniwas chhimpa
Ramniwas chhimpa

Reputation: 205

<?php

/**
* Converts numbers in string from western to eastern Arabic numerals.
*
* @param string $str Arbitrary text
* @return string Text with western Arabic numerals converted into eastern Arabic numerals.
*/
function arabic_w2e($str) {
$arabic_eastern = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
$arabic_western = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
return str_replace($arabic_western, $arabic_eastern, $str);
}

/**
* Converts numbers from eastern to western Arabic numerals.
*
* @param string $str Arbitrary text
* @return string Text with eastern Arabic numerals converted into western Arabic numerals.
*/
function arabic_e2w($str) {
$arabic_eastern = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
$arabic_western = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
return str_replace($arabic_eastern, $arabic_western, $str);
}

Upvotes: 1

Ramniwas chhimpa
Ramniwas chhimpa

Reputation: 205

You can do this by using this...

$standard = array("0","1","2","3","4","5","6","7","8","9"); $east_arabic = array(Insert numerals - my browser crashes when copy + pasting)

$string = str_replace($standard , $east_arabic , $string);

Upvotes: 0

Related Questions