PHP function code for converting RMB into uppercase letters _ PHP Tutorial

Source: Internet
Author: User
PHP function code for converting RMB numbers into uppercase letters. On the Internet, I saw a very interesting function for converting numbers in the php RMB amount to uppercase in Chinese. the essence of this function is to convert numbers into uppercase in Chinese. it was interesting to test it, if you enter a number at will, you will see an interesting function on the Internet for converting the php RMB amount to the Chinese capital. The essence of this function is to convert the numbers to the Chinese capital, which is interesting after testing, if you enter a number, you can print it in uppercase. new friends can give it a try and write a lot of interesting PHP conversion functions.

The code is as follows:


Function cny ($ ns ){
Static $ cnums = array ("zero", "one", "two", "three", "si", "Wu", "Lu", "Lu ", "Success", "fail "),
$ Cnyunits = array ("circle", "corner", "minute "),
$ Grees = array ("pick", "weight", "weight", "", "pick", "weight", "weight ");
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 );
}





The code is as follows:


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;
}
?>


Usage: you can directly pass the number parameter. the following instances are printed in uppercase. Output: tens of thousands of rows, one round, and one round

The code is as follows:


Echo cny ('000000 ');
?>

...

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.