$persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
$num = range(0, 9);
echo str_replace($persian, $num,'٢٢٢');
I am getting same arebic numbers in result. it is not converting to english numbers.
$persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
$num = range(0, 9);
echo str_replace($persian, $num,'٢٢٢');
I am getting same arebic numbers in result. it is not converting to english numbers.
You can do it with below code:-
<?php
function str_split_unicode($str, $length = 1) {
$tmp = preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);
if ($length > 1) {
$chunks = array_chunk($tmp, $length);
foreach ($chunks as $i => $chunk) {
$chunks[$i] = join('', (array) $chunk);
}
$tmp = $chunks;
}
return $tmp;
}
function convert($string) {
$data = '';
$persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
$num = range(0, 9);
foreach($string as $new_str){
$data .= str_replace($persian, $num, $new_str);
}
return $data;
}
$data = str_split_unicode('۰۲۳'); // convert number into single dimensional array
echo $new_data = convert($data); // pass that array to convert function and then concatenate the whole data to get final English number
?>
Output:- https://eval.in/527884
Reference taken from here and modified :- convert Persian/Arabic numbers to English numbers