直接贴代码

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

    <form method="post" action="#">
        <input name="money" value="<?php if(isset($_POST['act'])){echo $_POST['money'];}?>"></input>
        <input type="submit" value="开始转换" name="act"></input>
    </form>

</body>
</html>

<?php
    function change_num($i){
        switch($i){
            case '1': return "壹";
            case '2': return "贰";
            case '3': return "叁";
            case '4': return "肆";
            case '5': return "伍";
            case '6': return "陆";
            case '7': return "柒";
            case '8': return "捌";
            case '9': return "玖";
            case '0': return "零";
            defualt : return "参数错误";exit();
        }
    }

    function change_int1($i){
        switch($i){
            case '1':return "";
            case '2': return "拾";
            case '3': return "佰";
            case '0': return "千";
            defualt : return "参数错误";exit;
        }
    }

    function change_int2($i){
        switch($i){
            case '0': return "圆";
            case '1': return "万";
            case '2': return "亿";
            defualt : return "参数错误";exit;
        }
    }

    function change_flo($i){
        switch($i){
            case '1': return "角";
            case '2': return "分";
            defualt : return "参数错误";exit;
        }
    }

    $big_mon = "";
    if(isset($_POST['act'])){

        if(!is_numeric($_POST['money'])){
            exit("不是数字");
        }

        $money = $_POST['money'];

        $money_int = intval($money);

        $money_float = round(($money - $money_int),2);

        $len_int = strlen($money_int);
        $len_float = strlen($money_float);

        for($i=0;$i<$len_int;$i++){
            if($money[$i] != 0){
                $big_mon .= change_num($money[$i]).change_int1(($len_int-$i)%4);
            }elseif(isset($money[$i+1]) && $money[$i+1] !=0){
                $big_mon .= change_num($money[$i]);
            }

            if(($len_int-$i)%4==1){
                $big_mon .= change_int2(intval(($len_int-$i)/4));
            }
        }

        $n_jiao = intval($money_float*10);
        $n_fen = $money_float*100 - $n_jiao*10;

        if($n_jiao != 0){
            $big_mon .= change_num($n_jiao).change_flo(1);
        }elseif($n_fen != 0){
            $big_mon .= change_num($n_jiao);
        }

        if($n_fen != 0){
            $big_mon .= change_num($n_fen).change_flo(2);
        }

    }
    echo $big_mon;
?>