PHP数字转换中文汉字,汉语语法问题已处理
2013-03-26 08:23
260 查看
PHP数字转换中文汉字
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; }
相关文章推荐
- 中文在C/C++中的处理和汉字乱码问题
- 中文在C/C++中的处理和汉字乱码问题
- PHP中使用asort进行中文排序失效的问题处理
- php中json_encode处理gbk与gb2312中文乱码问题的解决方法
- phpword插件导出word文件时中文乱码问题处理方案
- jquery的ajax处理php返回数组,及json_encode中文为空的问题
- php htmlentities汉字中文乱码问题解决办法
- 中文在C/C++中的处理和汉字乱码问题(wchar_t)
- 中文在C/C++中的处理和汉字乱码问题(wchar_t)
- php处理json时中文问题的解决方法
- phpword插件导出word文件时中文乱码问题处理方案
- php GD图像处理 中文乱码的问题
- php json_encode 后js处理时对中文和韩文的问题
- 解决PHP中json_encode函数处理中文乱码的问题 两种方法
- jquery的ajax处理php返回数组,及json_encode中文问题
- PHP中处理截取汉字,出现乱码问题的2个类
- 【JavaEE】javaee中汉字中文值乱码问题处理
- php json_encode 后js处理时对中文和韩文的问题
- PHP中使用asort进行中文排序失效的问题处理
- PHP处理中文字符串中的特殊字符解决Oracle插入报错的问题