Skip to content

Instantly share code, notes, and snippets.

@daydaydrunk
Created October 11, 2012 03:01
Show Gist options
  • Select an option

  • Save daydaydrunk/3869919 to your computer and use it in GitHub Desktop.

Select an option

Save daydaydrunk/3869919 to your computer and use it in GitHub Desktop.

Revisions

  1. daydaydrunk renamed this gist Oct 11, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. daydaydrunk created this gist Oct 11, 2012.
    49 changes: 49 additions & 0 deletions up
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    <?php
    function trans($str){
    $str = ltrim($str,"0") * 1;
    $str = (string)$str;
    $Big = array(0=>"",1=>"壹",2=>"贰",3=>"叁",4=>"肆",5=>"伍",6=>"陆",7=>"柒",8=>"捌",9=>"玖");
    $loc = array(0=>"零",1=>"",2=>"拾",3=>"佰",4=>"仟");
    $level = array("","万","亿","兆");
    $result = NULL;
    $len = ceil(strlen($str)/4);
    $l = strlen($str)-1;
    $arr = array();
    //分段
    for($i = 0;$i < $len;$i++){
    for($p =0 ;$p < 4;$p++){
    if($l == -1) break; $arr[$i] .= $str[$l--];
    }
    $arr[$i] = strrev($arr[$i]);
    }
    $cou = count($arr);
    //分段转换
    for($i = $cou -1;$i > -1;$i--){
    //获取每段循环的次数
    $lo = $O = strlen($arr[$i]);
    //转换
    for($m = 0;$m < $O;$m++){
    //不是0
    if($arr[$i][$m] != 0){
    $locc = $loc[$lo];
    }else{
    //最后一位是0
    if(($m+1) == $O){
    $locc = NULL;
    }else{//中间存在的0
    if($arr[$i][$m + 1] != 0){//当下一个数字不为0的时候加“零”
    $locc = $loc[0];
    }else{
    $locc = NULL;
    }
    }
    }
    $lo--;
    $result .= $Big[$arr[$i][$m]].$locc;
    }
    $result .= $level[$i];

    }
    return $result;
    }
    echo trans($_GET["a"]);