Today to share the code is how to use PHP to make the case of the name currency conversion, the following is the actual cases, the need for a friend to refer to.
<?phpheader ("CHARSET=UTF-8;"); function Numtrmb ($num) {$d = Array ("0", "one", "II", "three", "premises", "WU", "Lu", "Qi", "ba", "JIU"), $e = Array (' meta ', ' Pick ', ' bai ', ' thousand ', ' million ', ' Pick million ', ' Bai million ', ' thousand million ', ' billion ', ' pick billion ', ' Bai billion ', ' thousand billion '; $p = Array (' Points ', ' corners '); $zheng = "whole"; $final = Array (); $inwan = 0;//Whether there are million $inyi = 0;//whether there are billions $len = 0;//the length after the decimal point $y = 0; $num = Round ($num, 2);//Accurate to sub if (strlen ($num) >) {return "Amount too large", die ();} if ($c = Strpos ($num, '. ')) {//have decimal points, $c a few $len =strlen ($num)-strpos ($num, '. ') before the decimal point -1;//decimal point There are several numbers}else{//no decimal point $c = strlen ($num); $zheng = ' whole ';} for ($i = 0; $i < $c; $i + +) {$bit _num = substr ($num, $i, 1 ); if ($bit _num! = 0 | | substr ($num, $i + 1, 1)! = 0) {@ $low = $low. $d [$bit _num];} if ($bit _num | | $i = = $c-1) {@ $lo W = $low. $e [$c-$i-1]; }} if ($len!=1) {for ($j = $len; $j >= 1; $j-) {$point _num = substr ($num, strlen ($num)-$j, 1); @ $low = $low. $d [$point _num]. $p [$j-1]; }}else{$point _num = substr ($num, strlen ($num)-$len, 1); $low = $low. $d [$point _num]. $p [$len];} $chinses= Str_split ($low, 3);//String conversion to array for ($x = count ($chinses)-1; $x >= 0; $x-) {if ($inwan = = 0 && $chinses [$x] = = $e [4]) {//filter duplicated million $final [$y + +] = $chinses [$x]; $inwan = 1; if ($inyi = = 0 && $chinses [$x] = = $e [8]) {//filter duplicate billion $final [$y + +] = $chinses [$x]; $inyi = 1; $inwan = 0; if ($chinses [$x]! = $e [4] && $chinses [$x]!== $e [8]) {$final [$y + +] = $chinses [$x];}} $newstr = (Array_reverse ($final)); $nstr = Join ($NEWSTR); if ((Substr ($num, 2, 1) = = ' 0 ') && (substr ($num,-1) <> 0)) {$nstr = substr ($nstr, 0, (strlen ($NSTR)-6)). ' 0 '. SUBSTR ($nstr,-6, 6); } $nstr = (Strpos ($nstr, ' 0 angle '))? Substr_replace ($nstr, "", Strpos ($nstr, ' 0 horns '), 6): $nstr; return $nstr = (substr ($nstr, -3,3) = = ' Yuan ')? $nstr. $zheng: $nstr;} echo NUMTRMB (965002.65);
Here's a look at the PHP case conversion function
1. Convert a string to lowercase
Strtolower (): This function converts all characters passed in the string argument to lowercase and puts the string back in a small form.
Cases:
<?php $str = "I want to FLY"; $str = Strtolower ($STR); Echo $str;? >
Output Result:
I want to fly
2. Turn characters into uppercase
Strtoupper (): This function, in contrast to the Strtolower function, converts all characters of the passed character argument to a large
Write and return the string in uppercase. The usage is the same as Strtolowe ().
3. Convert the first character of a string to uppercase
Usfilst (): The function is to change the first character of a string to uppercase, which returns a string with the first character capitalized.
Use the same as Strtolowe ().
4. Convert the first character of each word in a string to uppercase
Ucwords (): This function capitalizes the first character of each word of the passed-in string. As in "Hello World", after the function
After processing, the "Hello Word" is returned. Usage is the same as Strtolowe ().
Believe that you have seen these cases you have mastered the method, more wonderful please pay attention to the PHP Chinese network other related articles!
Related reading:
How PHP solves large traffic and high concurrency
PHP commodity seconds to kill timing implementation (to solve large traffic scenarios)
JavaScript data types and git use code explained