I'm using this function to replace UTF-8 characters representing numbers in text with 'normal' digits.I'm wondering if this is optimized code since this is using two str_replace()s.public static function convertArabicNumbers($string) {    //$engish = array(0,1,2,3,4,5,6,7,8,9);    $persian = array('', '', '', '', '', '', '', '', '', '');    $arabic = array('','','','','','','','','','');    $num = range(0, 9);    return str_replace($arabic, $num, str_replace($persian, $num, $string));}
Replacing Perisan and Arabic digits
php;performance;strings;converting;utf 8
You are right that this is not optimal (performance wise). You may want to consider two things:static variables (those values in there are constants no need to recreate them every time).merging the arrays.Consider the following code:public static function convertArabicNumbers($string) {    //$engish = array(0,1,2,3,4,5,6,7,8,9);    static $fromchar = array('', '', '', '', '', '', '', '', '', '',                             '','','','','','','','','','');    static $num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',                        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')    return str_replace($fromchar, $num, $string);}I am really uncertain about the right-to-left characters.... should they be transformed in the same way as the left-to-right ones? You're the expert on that one.Still, you get the idea....