Home Backend Development PHP Tutorial Function written in php to convert RMB numbers to RMB capital letters

Function written in php to convert RMB numbers to RMB capital letters

Nov 29, 2016 am 10:00 AM
php

Sometimes we need to randomly generate usernames and passwords in applications, which can greatly improve the security of the application. To generate random usernames and passwords in PHP, you can use the mt_rand function or the rand function. The application of the rand function in verification codes More, and generating long character random codes generally requires the mt_rand function.

Using PHP to generate random numbers can be applied in many places, such as designing random passwords for programs, applications for simulating dice games, rock-paper-scissors game applications, etc.

The following are two functional methods for generating random numbers in PHP:

I saw a very interesting PHP function on the Internet that converts RMB amount numbers into Chinese uppercase letters. The essence is to convert numbers into Chinese uppercase letters. I tested it and it was very interesting. Just enter any number and you can print it out in uppercase letters. Novice friends, give it a try and draw inferences from one example. You can also write many interesting PHP conversion functions. PHP code:

<?     
function cny($ns) {    
    static $cnums=array("零","壹","贰","叁","肆","伍","陆","柒",
"捌","玖"),    
        $cnyunits=array("圆","角","分"),    
        $grees=array("拾","佰","仟","万","拾","佰","仟","亿");
    list($ns1,$ns2)=explode(".",$ns,2);    
    $ns2=array_filter(array($ns2[1],$ns2[0]));    
    $ret=array_merge($ns2,array(implode("",_cny_map_unit(str_spl
it($ns
1),$grees)),""));    
    $ret=implode("",array_reverse(_cny_map_unit($ret,$cnyunits)));
    return str_replace(array_keys($cnums),$cnums,$ret);
}
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==&#39;0&#39;?&#39;&#39;:$x).($units[($l-1)
%$ul]);    
        else $n=is_numeric($xs[0][0])?$x:&#39;&#39;;
        array_unshift($xs,$n);    
    }    
    return $xs;    
}   
?>

Usage: Just pass the numeric parameters directly. In the example below, the numbers are printed in uppercase letters. Output: 10,000,200,100,211 yuan

PHP code

<?php   
 echo cny(&#39;12121&#39;);   
?>


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to get the current date and time in PHP? How to get the current date and time in PHP? Aug 31, 2025 am 01:36 AM

Usedate('Y-m-dH:i:s')withdate_default_timezone_set()togetcurrentdateandtimeinPHP,ensuringaccurateresultsbysettingthedesiredtimezonelike'America/New_York'beforecallingdate().

How to set an error reporting level in PHP? How to set an error reporting level in PHP? Aug 31, 2025 am 06:48 AM

Useerror_reporting()toseterrorlevelsinPHP,suchasE_ALLfordevelopmentor0forproduction,andcontroldisplayorloggingviaini_set()toenhancedebuggingandsecurity.

How to work with timestamps in PHP? How to work with timestamps in PHP? Aug 31, 2025 am 08:55 AM

Use time() to get the current timestamp, date() formats the time, and strtotime() converts the date string to a timestamp. It is recommended that the DateTime class handles time zone and date operations for complex operations.

How to get the class name of an object in PHP? How to get the class name of an object in PHP? Sep 01, 2025 am 04:48 AM

Useget_class($object)togettheclassnameatruntime;2.UseMyClass::classforcompile-timeclassnamestrings,especiallywithnamespaces;3.Insideaclassmethod,get_class($this)returnsthecurrentobject'sclassname.

Enter key not working on my keyboard Enter key not working on my keyboard Aug 30, 2025 am 08:36 AM

First,checkforphysicalissueslikedebrisordamageandcleanthekeyboardortestwithanexternalone;2.TesttheEnterkeyindifferentappstodetermineiftheissueissoftware-specific;3.Restartyourcomputertoresolvetemporaryglitches;4.DisableStickyKeys,FilterKeys,orToggleK

What is the difference between == and === in PHP? What is the difference between == and === in PHP? Sep 01, 2025 am 07:50 AM

===The values ​​and types are required to be the same, ==Only care about whether the values ​​are equal. For example, 5=="5" is true, but 5==="5" is false, depending on the type. ===No type conversion, more secure and strict.

233 Paradise web version is available for fun without downloading. 233 Paradise web address 233 Paradise web version is available for fun without downloading. 233 Paradise web address Sep 02, 2025 pm 02:03 PM

The entrance to the 233 Paradise web version to open and play is https://www.233leyuan.com. This platform does not require downloading and supports direct online play, providing rich game types, smooth operation experience and complete community interaction functions.

How to encrypt and decrypt data in PHP? How to encrypt and decrypt data in PHP? Sep 01, 2025 am 04:11 AM

Useopenssl_encrypt()andopenssl_decrypt()withAES-256-CBCforsecurePHPencryption.GeneratearandomIVperencryption,derivekeyviaSHA-256,andstoreIVwithciphertextusingbase64encoding.Fordecryption,extractIVandregeneratekeytorecoverplaintext.Alwaysvalidatedecry

See all articles