Php Arabic numerals convert Chinese characters to uppercase letters, _ PHP Tutorial

Source: Internet
Author: User
Tags learn php programming
Php Arabic numerals are converted to Chinese characters in uppercase ,. Php Arabic numerals are converted to Chinese RMB in uppercase. the example in this article shows the implementation code for converting php Arabic numerals to Chinese RMB in uppercase for your reference. the code is as follows: php Arabic numerals are converted to Chinese characters in uppercase,

The example in this article shares the implementation code of converting php Arabic numerals to Chinese RMB in uppercase for your reference. the specific code is as follows:

Code 1: php Arabic numerals are converted to Chinese characters in uppercase, with detailed comments

/*** Function for converting the numeric amount to the Chinese capital amount * String Int $ num the lowercase number to be converted or the lowercase String * return uppercase letter * **/function num_to_ RMB ($ num) {$ c1 = ""; $ c2 = ""; // no more accurate to the end of the minute, so leave only two decimal places $ num = round ($ num, 2); // Convert the number to an integer $ num = $ num * 100; if (strlen ($ num)> 10) {return "The amount is too large. Please check" ;}$ I = 0; $ c = ""; while (1) {if ($ I = 0) {// Obtain the last digit $ n = substr ($ num, strlen ($ num)-1, 1);} else {$ n = $ num % 10 ;} // Convert the last digit to Chinese every time. $ P1 = substr ($ c1, 3 * $ n, 3); $ p2 = substr ($ c2, 3 * $ I, 3); if ($ n! = '0' | ($ n = '0' & ($ p2 = '000000' | $ p2 = '000000' | $ p2 =' yuan '))) {$ c = $ p1. $ p2. $ c;} else {$ c = $ p1. $ c;} $ I = $ I + 1; // remove the last digit from the number $ num = $ num/10; $ num = (int) $ num; // end loop if ($ num = 0) {break ;}}$ j = 0; $ slen = strlen ($ c); while ($ j <$ slen) {// utf8 a Chinese character is equivalent to 3 characters $ m = substr ($ c, $ j, 6); // process many numbers with 0 values, remove a Chinese character "zero" if ($ m = 'zero meta' | $ m = '000000' | $ m = '000000' | $ m = 'zero ID ') {$ left = substr ($ c, 0, $ j); $ right = substr ($ c, $ j + 3); $ c = $ left. $ right; $ j = $ J-3; $ slen = $ slen-3;} $ j = $ j + 3 ;} // This is to remove the last "zero" word like 23.0 if (substr ($ c, strlen ($ c)-3, 3) = '0 ') {$ c = substr ($ c, 0, strlen ($ c)-3);} // add the processed Chinese characters to an integer if (empty ($ c )) {return "zero yuan";} else {return $ c. "whole" ;}} echo num_to_ RMB (23000000.00); // tens of thousands of RMB

Code 2: php Arabic numerals converted to Chinese capital

// Function NumToCNMoney ($ num, $ mode = true, $ sim = true) {if (! Is_numeric ($ num) return 'contains non-decimal characters! '; $ Char = $ sim? Array ('0', '1', '2', '3', '4', '5', '6', '7', '8 ', '9'): array ('0', 'yi', 'er', 'san', 'siz', 'wu', 'Lu', 'region ', 'authorization', 'authorization'); $ unit = $ sim? Array ('', '10', '100', '100','', '100', '000000'): array ('', 'pick', 'handler', 'handler', ', 'handler', 'handler'); $ retval = $ mode? 'Meta': 'point'; // if (strpos ($ num ,'. ') {list ($ num, $ dec) = explode ('. ', $ num); $ dec = strval (round ($ dec, 2); if ($ mode) {$ retval. = "{$ char [$ dec ['0']} {$ char [$ dec ['1 ";} else {for ($ I = 0, $ c = strlen ($ dec); $ I <$ c; $ I ++) {$ retval. = $ char [$ dec [$ I] ;}}// integer part $ str = $ mode? Strrev (intval ($ num): strrev ($ num); for ($ I = 0, $ c = strlen ($ str); $ I <$ c; $ I ++) {$ out [$ I] = $ char [$ str [$ I]; if ($ mode) {$ out [$ I]. = $ str [$ I]! = '0 '? $ Unit [$ I % 4]: ''; if ($ I> 1 and $ str [$ I] + $ str [$ i-1] = 0) {$ out [$ I] = '';} if ($ I % 4 = 0) {$ out [$ I]. = $ unit [4 + floor ($ I/4)] ;}}$ retval = join ('', array_reverse ($ out )). $ retval; return $ retval;} echo (NumToCNMoney (2.55 )."
"); Echo (NumToCNMoney (2.55 )."
"); Echo (NumToCNMoney (7965 )."
"); Echo (NumToCNMoney (7965,1, 0 )."
"); Echo (NumToCNMoney (155555555.68 )."
"); Echo (NumToCNMoney (155555555.68 )."
"); Echo (NumToCNMoney (0.8888888 )."
"); Echo (NumToCNMoney (0.8888888 )."
"); Echo (NumToCNMoney (99999999999 )."
"); Echo (NumToCNMoney (99999999999,1, 0 )."
");

I hope this article will help you learn php programming.

Articles you may be interested in:
  • Php implements a function for converting Arabic numerals to Chinese numerals
  • Php separates strings into string arrays by uppercase letters
  • Code for converting lowercase amount to uppercase amount using PHP (accurate to minute)
  • PHP function code for converting RMB into uppercase letters
  • Php converts all strings to uppercase or lowercase letters.

Example :...

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.