Php numeric to Chinese character function algorithm php numeric to Chinese character function ************************ numeric to Chinese character *** * ******************* functiondel0 ($ num) remove the 0 {return. intval ($ num);} functionn2c ($ x) function algorithm for converting a single number to a Chinese character {$ arr_n php number to a Chinese character
Functions for converting php numbers to Chinese characters
/******************** Convert numbers to Chinese characters *************** * ******/function del0 ($ num) // remove the 0 {return "". intval ($ num);} function n2c ($ x) // change a single digit to a Chinese character {$ arr_n = array ("zero", "one", "two ", "3", "4", "5", "6", "7", "8", "9", "10 "); return $ arr_n [$ x];} function num_r ($ abcd) // read the Value (4 bits) {$ arr = array (); $ str = ""; // the value of the Chinese character after reading $ flag = 0; // whether the bit is zero $ flag_end = 1; // whether it ends with "zero" $ 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-1-$ j]); // forward from the back to the Chinese character // echo $ ch; // echo"
"; If ($ ch =" zero "& $ flag = 0) {// if it is the first zero $ flag = 1; // This bit is zero $ str = $ ch. $ str; // add the Chinese character value string continue;} elseif ($ ch = "0") {// if not the first zero, continue;} $ flag = 0; // This bit is not zero switch ($ j) {case 0: $ str = $ ch; $ flag_end = 0; break; // The first (end ), case 1: $ str = $ ch. "10 ". $ str; break; // Second case 2: $ str = $ ch. "hundred ". $ str; break; // The Third case 3: $ str = $ ch. "thousand ". $ str; break; // fourth digit }}if ($ flag_end = 1) // if it ends with "zero" {mb_internal_encoding ("UTF-8 "); $ str = mb_substr ($ str, 0, mb_strlen ($ str)-1 ); // remove "zero"} if ($ arrlen = 2 & $ arr [0] = 1) {$ str = substr ($ str, 2 );} 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 the number of digits reaches nine, read" "bits {$ y = substr ($ num_real,-9, 1 ); // echo $ y; $ wsbq = substr ($ num_real,-8, 4); $ gsbq = substr ($ num_real,-4 ); $ a = num_r (del0 ($ gsbq); $ B = num_r (del0 ($ wsbq )). "Ten Thousand"; $ c = num_r (del0 ($ y )). "";} elseif ($ numlen <= 8 & $ numlen> = 5) // if it is greater than or equal to "" {$ wsbq = substr ($ num_real, 0, $ numlen-4); $ gsbq = substr ($ num_real,-4); $ a = num_r (del0 ($ gsbq); $ B = num_r (del0 ($ wsbq )). "Ten Thousand"; $ c = "";} elseif ($ numlen <= 4) // if the value 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 ;} ***************** ***/
?