To turn numbers into Chinese characters Wrote one of his own
- function Number2chinese ($num, $m = 1) {
- Switch ($m) {
- Case 0:
- $CNum = Array (
- Array (' 0 ', ' one ', ' II ', ' three ', ' establishments ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '),
- Array (', ' Pick ', ' bai ', ' thousand '),
- Array (', ' million ', ' Yi ', ' billions ')
- );
- Break
- Default
- $CNum = Array (
- Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine '),
- Array (' ', ' ten ', ' hundred ', ' thousand '),
- Array (', ' million ', ' billion ', ' trillion ')
- );
- Break
- }
- $cNum = Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' V ', ' VI ', ' VII ', ' VIII ', ' IX ');
- if (Is_integer ($num)) {
- $int = (string) $num;
- } else if (Is_numeric ($num)) {
- $num = Explode ('. ', (String) floatval ($num));
- $int = $num [0];
- $FL = Isset ($num [1])? $num [1]: FALSE;
- }
- Length
- $len = strlen ($int);
- Chinese
- $chinese = Array ();
- Reversed number
- $str = Strrev ($int);
- for ($i = 0; $i < $len; $i +=4) {
- $s = Array (0=> $str [$i], 1=> $str [$i +1], 2=> $str [$i +2], 3=> $str [$i +3]);
- $j = ";
- Thousands
- if ($s [3]!== ") {
- $s [3] = (int) $s [3];
- if ($s [3]!== 0) {
- $j. = $CNum [0][$s [3]]. $CNum [1][3];
- } else {
- if ($s [2]! = 0 | | $s [1]! = 0 | | $s [0]!=0] {
- $j. = $CNum [0][0];
- }
- }
- }
- Hundred
- if ($s [2]!== ") {
- $s [2] = (int) $s [2];
- if ($s [2]!== 0) {
- $j. = $CNum [0][$s [2]]. $CNum.
- } else {
- if ($s [3]!=0 && ($s [1]! = 0 | | $s [0]!=0]) {
- $j. = $CNum [0][0];
- }
- }
- }
- Ten
- if ($s [1]!== ") {
- $s [1] = (int) $s [1];
- if ($s [1]!== 0) {
- $j. = $CNum [0][$s [1]]. $CNum [1][1];
- } else {
- if ($s [0]!=0 && $s [2]! = 0) {
- $j. = $CNum [0][$s [1]];
- }
- }
- }
- Bit
- if ($s [0]!== ") {
- $s [0] = (int) $s [0];
- if ($s [0]!== 0) {
- $j. = $CNum [0][$s [0]]. $CNum [1][0];
- } else {
- $j. = $CNum [0][0];
- }
- }
- $j. = $CNum [2][$i/4];
- Array_unshift ($chinese, $j);
- }
- $chs = Implode (' ', $chinese);
- if ($FL) {
- $chs. = ' point ';
- For ($i =0, $j =strlen ($FL), $i < $j; $i + +) {
- $t = (int) $FL [$i];
- $chs. = $str [0][$t];
- }
- }
- return $chs;
- }
Copy Code
- function Number2chinese ($num, $m = 1) {
- Switch ($m) {
- Case 0:
- $CNum = Array (
- Array (' 0 ', ' one ', ' II ', ' three ', ' establishments ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU '),
- Array (', ' Pick ', ' bai ', ' thousand '),
- Array (', ' million ', ' Yi ', ' billions ')
- );
- Break
- Default
- $CNum = Array (
- Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine '),
- Array (' ', ' ten ', ' hundred ', ' thousand '),
- Array (', ' million ', ' billion ', ' trillion ')
- );
- Break
- }
- $cNum = Array (' 0 ', ' one ', ' two ', ' three ', ' four ', ' V ', ' VI ', ' VII ', ' VIII ', ' IX ');
- if (Is_integer ($num)) {
- $int = (string) $num;
- } else if (Is_numeric ($num)) {
- $num = Explode ('. ', (String) floatval ($num));
- $int = $num [0];
- $FL = Isset ($num [1])? $num [1]: FALSE;
- }
- Length
- $len = strlen ($int);
- Chinese
- $chinese = Array ();
- Reversed number
- $str = Strrev ($int);
- for ($i = 0; $i < $len; $i +=4) {
- $s = Array (0=> $str [$i], 1=> $str [$i +1], 2=> $str [$i +2], 3=> $str [$i +3]);
- $j = ";
- Thousands
- if ($s [3]!== ") {
- $s [3] = (int) $s [3];
- if ($s [3]!== 0) {
- $j. = $CNum [0][$s [3]]. $CNum [1][3];
- } else {
- if ($s [2]! = 0 | | $s [1]! = 0 | | $s [0]!=0] {
- $j. = $CNum [0][0];
- }
- }
- }
- Hundred
- if ($s [2]!== ") {
- $s [2] = (int) $s [2];
- if ($s [2]!== 0) {
- $j. = $CNum [0][$s [2]]. $CNum.
- } else {
- if ($s [3]!=0 && ($s [1]! = 0 | | $s [0]!=0]) {
- $j. = $CNum [0][0];
- }
- }
- }
- Ten
- if ($s [1]!== ") {
- $s [1] = (int) $s [1];
- if ($s [1]!== 0) {
- $j. = $CNum [0][$s [1]]. $CNum [1][1];
- } else {
- if ($s [0]!=0 && $s [2]! = 0) {
- $j. = $CNum [0][$s [1]];
- }
- }
- }
- Bit
- if ($s [0]!== ") {
- $s [0] = (int) $s [0];
- if ($s [0]!== 0) {
- $j. = $CNum [0][$s [0]]. $CNum [1][0];
- } else {
- $j. = $CNum [0][0];
- }
- }
- $j. = $CNum [2][$i/4];
- Array_unshift ($chinese, $j);
- }
- $chs = Implode (' ', $chinese);
- if ($FL) {
- $chs. = ' point ';
- For ($i =0, $j =strlen ($FL), $i < $j; $i + +) {
- $t = (int) $FL [$i];
- $chs. = $str [0][$t];
- }
- }
- return $chs;
- }
Copy Code |