在打印订单的时候,如果是货到付款,那么可能就需要中文大写的金额了,这个EMS是必须的!

但是ecshop并没有这样的功能,怎么办呢?

只好自己写了一个,可能存在大量Bug,求大师帮忙优化!谢谢!

 
  
  1. function nature2zh($price
  2.       $str = ''
  3.       $arr_big5 = array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖'); 
  4.       $arr_unit = array('''''拾''佰''仟''万'); 
  5.  
  6.       if(strpos($price'.') === false) 
  7.       { 
  8.             $temp[0] = $price
  9.       } 
  10.       else 
  11.       { 
  12.             $temp = explode('.'$price); 
  13.       } 
  14.  
  15.       $j = $k = strlen($temp[0]); 
  16.       for ($i = 0; $i < $j$i++) 
  17.       { 
  18.             if ($temp[0][$i] > 0) 
  19.             { 
  20.                   $str .= $arr_big5[$temp[0][$i]]; 
  21.                   $k > 2 && $str .= $arr_unit[$k--]; 
  22.                   $m = 0; 
  23.             } 
  24.             else if ($m == 0 && $j-$i>1) 
  25.             { 
  26.                   $str .= $arr_big5[$temp[0][$i]]; 
  27.                   $k--; 
  28.                   $m++; 
  29.             } 
  30.             else 
  31.             { 
  32.                   $k--; 
  33.                   continue
  34.             } 
  35.       } 
  36.  
  37.       if (isset($temp[1]) && $temp[1] > 0) 
  38.       { 
  39.             $str .= '元'
  40.             $temp[1][0] > 0 && $str .= $arr_big5[$temp[1][0]].'角'
  41.             isset($temp[1][1]) && $temp[1][1] > 0 && $str .= $arr_big5[$temp[1][1]].'分'
  42.       } 
  43.       else 
  44.       { 
  45.             $str .= '元整'
  46.       } 
  47.  
  48.       return $str