PHP 中文数字替换阿拉伯数字

image

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* 中文数字替换阿拉伯数字
*/
function switchChnNumber($time){
if(!empty($time)){
$replaceValueC = [
"一"=>1,"二"=>2,"两"=>2,"三"=>3,"四"=>4,"五"=>5,
"六"=>6,"七"=>7,"八"=>8,"九"=>9,"十"=>'0',
"百"=>'00',"千"=>'000',"万"=>'0000',"块"=>'元'
];
//拆分含有中文的字符串
$arrTime = preg_split('/(?<!^)(?!$)/u', $time);
foreach ($arrTime as $key => $value){
if(isset($replaceValueC[$value]) && $replaceValueC[$value] != ''){
$arrTime[$key] = $replaceValueC[$value];
}else{
$arrTime[$key] = $value;
}
}
return implode("", $arrTime);
}else{
return $time;
}
}
-------------本文结束感谢您的阅读-------------
0%