问题
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 !
回答1:
<?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);
}
回答2:
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);
回答3:
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
来源:https://stackoverflow.com/questions/24862156/symfony-2-how-to-make-numbers-appear-in-western-arabic