• PHP 阿拉伯数字转中文表述


    如101转成一百零一

    function num2cn($number) {
        $number = intval ( $number );
        $capnum = array (
                "零",
                "一",
                "二",
                "三",
                "四",
                "五",
                "六",
                "七",
                "八",
                "九" 
        );
        $capdigit = array (
                "",
                "十",
                "百",
                "千",
                "万" 
        );
        
        $data_arr = str_split ( $number );
        $count = count ( $data_arr );
        for($i = 0; $i < $count; $i ++) {
            $d = $capnum [$data_arr [$i]];
            $arr [] = $d != '零' ? $d . $capdigit [$count - $i - 1] : $d;
        }
        $cncap = implode ( "", $arr );
        
        $cncap = preg_replace ( "/(零)+/", "0", $cncap ); // 合并连续“零”
        $cncap = trim ( $cncap, '0' );
        $cncap = str_replace ( "0", "零", $cncap ); // 合并连续“零”
        $cncap == '一十' && $cncap = '十';
        $cncap == '' && $cncap = '零';
        return $cncap;
    }
  • 相关阅读:
    Add Binary <leetcode>
    那些坑
    面试集锦
    随看随记
    View的事件处理流程
    android studio view.setId报错
    EditText的hint不显示
    EditText 焦点
    Android拍照的那些事
    微信支付提示签名错误
  • 原文地址:https://www.cnblogs.com/zjj1990/p/8126071.html
Copyright © 2020-2023  润新知