Home  >  Article  >  Backend Development  >  Send a PHP RMB amount number and convert it to Chinese capital letters_PHP Tutorial

Send a PHP RMB amount number and convert it to Chinese capital letters_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:08972browse

To convert the RMB amount to Chinese capital letters, Boring also wrote a code with the same function in PHP:

Php code
function cny($ns) {
static $cnums=array("zero", "one", "two", "three", "four", "five", "lu", "旒", "eight", "玖"),
        $cnyunits=array("circle", "angle", "minute"),
          $grees=array("十","百","千","万","十","百","千","千亿");
List($ns1,$ns2)=explode(".",$ns,2);
$ns2=array_filter(array($ns2[1],$ns2[0]));
$ret=array_merge($ns2,array(implode("",_cny_map_unit(str_split($ns1),$grees)),""));
$ret=implode("",array_reverse(_cny_map_unit($ret,$cnyunits)));
Return str_replace(array_keys($cnums),$cnums,$ret);
}
function _cny_map_unit($list,$units) {
$ul=count($units);
$xs=array();
foreach (array_reverse($list) as $x) {
          $l=count($xs);
if ($x!="0" || !($l%4)) $n=($x=='0'?'':$x).($units[($l-1)%$ ul]);
            else $n=is_numeric($xs[0][0])?$x:''; ​​
         array_unshift($xs,$n);
}  
Return $xs;
}

This article is from "Jam's Pier"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478678.htmlTechArticleThe RMB amount figures were converted to Chinese capital letters. Boring also wrote a code with the same function in PHP: Php code function cny( $ns) { static $cnums=array(zero, one, two, three, four, five, land, seven, eight, nine...
Statement:
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