Search code examples
phpsymfonylocale

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 !


Solution

  • <?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);
    }