打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
PHP数字转换中文汉字,汉语语法问题已处理

PHP数字转换中文汉字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function number2Chinese($num$m = 1) {
switch($m) {
case 0:
$CNum array(
array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖'),
array('','拾','佰','仟'),
array('','萬','億','萬億')
);
break;
default:
$CNum array(
array('零','一','二','三','四','五','六','七','八','九'),
array('','十','百','千'),
array('','万','亿','万亿')
);
break;
}
// $cNum = array('零','一','二','三','四','五','六','七','八','九');
if (is_integer($num)) {
$int = (string)$num;
else if (is_numeric($num)) {
$num explode('.', (string)floatval($num));
$int $num[0];
$fl  = isset($num[1]) ? $num[1] : FALSE;
}
// 长度
$len strlen($int);
// 中文
$chinese array();
// 反转的数字
$str strrev($int);
for($i = 0; $i<$len$i+=4 ) {
$s array(0=>$str[$i], 1=>$str[$i+1], 2=>$str[$i+2], 3=>$str[$i+3]);
$j '';
// 千位
if ($s[3] !== '') {
$s[3] = (int) $s[3];
if ($s[3] !== 0) {
$j .= $CNum[0][$s[3]].$CNum[1][3];
else {
if ($s[2] != 0 || $s[1] != 0 || $s[0]!=0) {
$j .= $CNum[0][0];
}
}
}
// 百位
if ($s[2] !== '') {
$s[2] = (int) $s[2];
if ($s[2] !== 0) {
$j .= $CNum[0][$s[2]].$CNum[1][2];
else {
if ($s[3]!=0 && ($s[1] != 0 || $s[0]!=0) ) {
$j .= $CNum[0][0];
}
}
}
// 十位
if ($s[1] !== '') {
$s[1] = (int) $s[1];
if ($s[1] !== 0) {
$j .= $CNum[0][$s[1]].$CNum[1][1];
else {
if ($s[0]!=0 && $s[2] != 0) {
$j .= $CNum[0][$s[1]];
}
}
}
// 个位
if ($s[0] !== '') {
$s[0] = (int) $s[0];
if ($s[0] !== 0) {
$j .= $CNum[0][$s[0]].$CNum[1][0];
else {
// $j .= $CNum[0][0];
}
}
$j.=$CNum[2][$i/4];
array_unshift($chinese$j);
}
$chs = implode(''$chinese);
if ($fl) {
$chs .= '点';
for($i=0,$j=strlen($fl); $i<$j$i++) {
$t = (int)$fl[$i];
$chs.= $str[0][$t];
}
}
return $chs;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
PHP substr 汉字 乱码 自构函数
php基础函数数组函数字符串函数
Java开发新手数组方法的应用猜字母游戏
PHP的文件操作与算法实现的面试题示例
php下intval()和(int)转换使用与区别
C# 拼音转换-工具类
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服