在打印订单的时候,如果是货到付款,那么可能就需要中文大写的金额了,这个EMS是必须的!
但是ecshop并没有这样的功能,怎么办呢?
只好自己写了一个,可能存在大量Bug,求大师帮忙优化!谢谢!
- function nature2zh($price)
- {
- $str = '';
- $arr_big5 = array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
- $arr_unit = array('', '', '拾', '佰', '仟', '万');
- if(strpos($price, '.') === false)
- {
- $temp[0] = $price;
- }
- else
- {
- $temp = explode('.', $price);
- }
- $j = $k = strlen($temp[0]);
- for ($i = 0; $i < $j; $i++)
- {
- if ($temp[0][$i] > 0)
- {
- $str .= $arr_big5[$temp[0][$i]];
- $k > 2 && $str .= $arr_unit[$k--];
- $m = 0;
- }
- else if ($m == 0 && $j-$i>1)
- {
- $str .= $arr_big5[$temp[0][$i]];
- $k--;
- $m++;
- }
- else
- {
- $k--;
- continue;
- }
- }
- if (isset($temp[1]) && $temp[1] > 0)
- {
- $str .= '元';
- $temp[1][0] > 0 && $str .= $arr_big5[$temp[1][0]].'角';
- isset($temp[1][1]) && $temp[1][1] > 0 && $str .= $arr_big5[$temp[1][1]].'分';
- }
- else
- {
- $str .= '元整';
- }
- return $str;
- }
转载于:https://blog.51cto.com/nixus/972362