注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
安全:10个常用数字证书应用实例
小技巧:Win XP下数字CD播放模式
取消Windows XP下驱动程序数字签
数字签名(ms)
用BP网络算法实现对含噪声0到9数
C++小技巧:用Socket接收和转换数
用Socket接收和转换数字和字符串
VC数字图像处理编程讲座之五
VC数字图像处理编程讲座之四
VC数字图像处理编程讲座之三
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> PHP >> 文章正文
把数字转换成英语或是汉语表达
作者:longnetpro  来源:ChinaUnix.net  点击:  更新:2006-12-19
简介:
rator($trans[$rr]);
            }
         }
      }
      $ss = '';
      if ($sh != '' && $sr != ''){
         $ss = $sh. $this->addSeperator('and') .$sr;
      }else{
         $ss = $sh.$sr;
      }
      return $ss;
   }
   
   function trans_int($int){
      if ($int <= 20) return $this->addSeperator($this->resource['group_int'][intval($int)]);
      $groups = explode(',', $this->split_group($int));
      $groups = array_reverse($groups);
      $cgroup = $this->resource['group']['group_number'];
      $result = '';
      foreach($groups as $key => $group_int){
         $sgroup = '';
         $k = $key % $cgroup;
         if ((int)$group_int != 0){
            $sgroup = $this->resource['group'][$k];
            $sgroup = $this->addSeperator($sgroup);
            $sgroup = $this->trans_group_int($group_int).$sgroup;
         }
         $ss = '';
         if ($k == 0 && $key >= $cgroup)
            $ss = $this->addSeperator($this->resource['group'][$cgroup]);
         $result = $sgroup.$ss.$result;
      }
      return $result;
   }
   
   function trans_fraction($fraction){
      if ($fraction == '') return '';
      $fraction = preg_replace('/([0-9])/e', '$this->addSeperator($this->resource[\'group_int\'][\\1])', $fraction);
      return $fraction;
   }
   
   function getText($isupper = false){
      $text = parent::getText();
      if ($isupper){
         $text = strtoupper($text);
      }
      return $text;
   }
}

//---------------------------------------------------------------------------

class TextNumber_zh_CN extends TextNumber
{
   var $groupLength = 4;
   var $wordSeperated = false;

   function TextNumber_zh_CN(){
      $this->__construct();
   }
   
   function __construct(){
      $this->resource = array(
         'group_int' => array(
            0 => '零',
            1 => '一',
            2 => '二',
            3 => '三',
            4 => '四',
            5 => '五',
            6 => '六',
            7 => '七',
            8 => '八',
            9 => '九'
         ),
         'group_int_digital' => array(
            0 => '',
            1 => '十',
            2 => '百',
            3 => '千'
         ),
         'group' => array(
            0 => '',
            1 => '万',
            2 => '亿',
            3 => '兆',
            '-' => '负',
            '.' => '点',
            'group_number' => 3
         ),
         'trans_upper' => array(
            '一' => '壹',
            '二' => '贰',
            '三' => '叁',
            '四' => '肆',
            '五' => '伍',
            '六' => '陆',
            '七' => '柒',
            '八' => '捌',
            '九' => '玖',
            '十' => '拾',
            '百' => '佰',
            '千' => '仟'
         )
      );
   }
   
   function trans_group_int($group_int){
      $si = strrev($group_int);
      $ss = '';
      $i = 0;
      if (preg_match('/^([0]+)/', $si, $matches)){
         $i = strlen($matches[1]);
      }
      for(; $i < strlen($si); $i++){
         $s = ($si{$i} == '0')? '' : $this->addSeperator($this->resource['group_int_digital'][$i]);
         $ss = $si{$i}.$s.$ss;
      }
      return $ss;
   }
   
   function trans_int($int){
      if ($int < 10) return $this->addSeperator($this->resource['group_int'][intval($int)]);
      /*
      if ($int < 20){
         $sint = $this->addSeperator($this->resource['group_int'][10]);
         $sint .= $this->addSeperator($this->resource['group_int'][$int % 10]);
         return $sint;
      }
      */
      $groups = explode(',', $this->split_group($int));
      $groups = array_reverse($groups);
      $cgroup = $this->resource['group']['group_number'];
      $result = '';
      foreach($groups as $key => $group_int){
         $sgroup = '';
         $k = $key % $cgroup;
         if ((int)$group_int != 0){
            $sgroup = $this->resource['group'][$k];
            $sgroup = $this->addSeperator($sgroup);
            $sgroup = $this->trans_group_int($group_int).$sgroup;
            if ($k != 0 && substr($group_int, -1) == '0')
               $sgroup .= '0';
         }else{
            $sgroup = '0';
         }
         $ss = '';
         if ($k == 0 && $key >= $cgroup){
            $ss = $this->addSeperator($this->resource['group'][$cgroup]);
            if (substr($group_int, -1) == '0')
               $ss .= '0';
         }
         $result = $sgroup.$ss.$result;
      }
      $result = preg_replace('/[0]+/', '0', $result);
      $result = preg_replace('/(^|[^1-9])0([^1-9]|$)/', '\\1\\2', $result);
      $result = preg_replace('/([0-9])/e', '$this->addSeperator($this->resource[\'group_int\'][\\1])', $result);
      return $result;
   }
   
   function trans_fraction($fraction){
      if ($fraction == '') return '';
      $fraction = preg_replace('/([0-9])/e', '$this->addSeperator($this->resource[\'group_int\'][\\1])', $fraction);
      return $fraction;
   }
   
   function getText($isupper

上一页  [1] [2] [3] 下一页






  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务