How to convert lowercase numbers to uppercase in php

藏色散人
Release: 2023-03-08 15:58:02
Original
2469 people have browsed it

php How to convert lowercase numbers to uppercase: First create a PHP sample file; then use the "private function getChineseNumber($num, $mode = true){...}" method to convert lowercase numbers to uppercase That’s it.

How to convert lowercase numbers to uppercase in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php realizes the conversion of Arabic numerals to Chinese uppercase

/**
     *  阿拉伯数字到中文大写转换
     *
     * @param $num
     * @param bool $mode
     * @return string
     */
    private function getChineseNumber($num, $mode = true)
    {
        $char = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
        $dw = array("", "拾", "佰", "仟", "", "万", "亿", "兆");
        $dec = "点";
        $retval = "";
        if ($mode) {
            preg_match_all("/^0*(\d*)\.?(\d*)/", $num, $ar);
        } else {
            preg_match_all("/(\d*)\.?(\d*)/", $num, $ar);
        }
 
        if ($ar[2][0] != 00) {
            $retval = $dec . $this->getChineseNumber($ar[2][0], false); //如果有小数,则用递归处理小数
        }
 
        if ($ar[1][0] != 00) {
            $str = strrev($ar[1][0]);
            for ($i = 0; $i < strlen($str); $i++) {
                $out[$i] = $char[$str[$i]];
                if ($mode) {
                    $out[$i] .= $str[$i] != "0" ? $dw[$i % 4] : "";
 
                    if ($str[$i] + $str[($i - 1 >= 0) ? $i - 1 : 0] == 0) {
                        $out[$i] = "";
                    }
 
                    if ($i % 4 == 0) {
                        $out[$i] .= $dw[4 + floor($i / 4)];
                    }
                }
            }
 
            $retval = join("", array_reverse($out)) . $retval;
        }
 
        return $retval;
    }
Copy after login

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to convert lowercase numbers to uppercase in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!