PHP numeric lowercase to uppercase function

Source: Internet
Author: User

When PHP converts Arabic numerals to Chinese, it is necessary to define a conversion algorithm:
<?php/converts a number to a Chinese character, such as 1210 to 1210 $num = "842105580",//nine-digit function del0 ($num)//Removes the 0 {return "" in front of the number field. Intval ($num); function n2c ($x)//single digit variable kanji {$arr _n = array ("0", "one", "two", "three", "four", "five", "six", "seven", "Eight", "IX", "ten"), return $arr _n[$x];} function n Um_r ($ABCD)//Read value (4 bits) {$arr = array (); $str = ""; The value of Chinese characters after reading is $flag = 0; Whether the bit is zero $flag _end = 1; Whether to end with "0" $size _r = strlen ($ABCD); for ($i =0; $i < $size _r; $i + +) {$arr [$i] = $ABCD {$i};} $arrlen = count ($arr); for ($j =0; $j < $arrlen; $j + +) {$ch = N2C ($arr [$arrlen-$j]);//forward to the Chinese character echo $ch; echo ""; if ($ch = = "0" && $flag = = 0) {//If it is the first 0 $flag = 1;//The bit is zero $str = $ch. $str;//Add Chinese character value string continue;} ElseIf ($ch = = "0") {//If it is not the first zero continue;} $flag = 0; This bit is not 0 switch ($j) {case 0: $str = $ch; $flag _end = 0; break;//First bit (end), no "0" end Case 1: $str = $ch. " Ten ". $str; Break Second Case 2: $str = $ch. " Hundred ". $str; Break Third Case 3: $str = $ch. " Thousand ". $str; Break Fourth bit} if ($flag _end = = 1)//If End with "0" {mb_internal_encoding ("UTF-8"); $str = Mb_substr ($STR, 0, Mb_strlen ($str)-1); Remove the "0"} return $str; } function Num2ch ($num)//Overall read conversion {$num _real = del0 ($num);//Remove the preceding "0" $numlen = strlen ($num _real); echo "numlen=". $numlen. " "; if ($numlen >= 9)//If full nine bits, read "million" bit {$y =substr ($num _real,-9, 1);//echo $y; $wsbq = substr ($num _real, 8, 4); $GSBQ = Subs TR ($num _real,-4); $a = Num_r (Del0 ($GSBQ)); $b = Num_r (Del0 ($WSBQ)). " Million "; $c = Num_r (Del0 ($y)). " Billion "; }elseif ($numlen <= 8 && $numlen >= 5)//if greater than or equal to "million" {$wsbq = substr ($num _real, 0, $numlen-4); $GSBQ = substr ( $num _real,-4); $a = Num_r (Del0 ($GSBQ)); $b = Num_r (Del0 ($WSBQ)). " Million "; $c = ""; }elseif ($numlen <= 4)//If it is less than or equal to "thousand" {$GSBQ = substr ($num _real,-$numlen); $a = Num_r (Del0 ($GSBQ)); $b = ""; $c = "";} $ch _ num = $c. $b. $a; return $ch _num; } echo $num. ""; Digital echo num2ch ($num); Chinese character echo ""; echo num2ch ("1240");?>

PHP numeric lowercase to uppercase function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.