- Test ();
- /**
- * Test
- */
- function Test () {
- Echo cntoint (' one '); 1
- Echo cntoint (' ten '); 10
- Echo cntoint (' 11 '); 11
- Echo cntoint (' 110 '); 110
- echo cntoint (' 1001 '); 1001
- echo cntoint (' 10,101 '); 10101
- echo cntoint (' 113,003,001 '); 113003001
- echo cntoint (' 1000 trillion '); 11.0E+15
- }
- /**
- * Chinese to Digital
- * @param String $var The number of Chinese to parse
- * @param Int $start Initial value
- * @return int
- */
- function Cntoint ($var, $start = 0) {
- if (Is_numeric ($var)) {
- return $var;
- }
- if (intval ($var) = = = 0) {
- $splits = Array (' billion ' = + 100000000, ' million ' + 10000);
- $chars = Array (' million ' = 10000, ' thousand ' = 1000, ' hundred ' = 100, ' ten ' = 10, ' One ' + 1, ' 0 ' = 0);
- $Ints = Array (' 0 ' = + 0, ' one ' = 1, ' two ' = 2, ' three ' = ' 3, ' four ' = 4, ' Five ' = 5, ' six ' = ' 6 ', ' seven ' = ' 7 ', ' eight ' = 8, ' Nine ' = 9, ' Ten ' = 10 ';
- $var = Str_replace (' 0 ', "", $var);
- foreach ($splits as $key = = $step) {
- if (Strpos ($var, $key)) {
- $strs = Explode ($key, $var);
- $start + = Cntoint (Array_shift ($strs)) * $STEP;
- $var = Join ("', $strs);
- }
- }
- foreach ($chars as $key = = $step) {
- if (Strpos ($var, $key)!== FALSE) {
- $vs = Explode ($key, $var);
- if ($vs [0] = = = = "") {
- $vs [0] = ' one ';
- }
- $start + = $Ints [Array_shift ($VS)] * $STEP;
- $var = Join ("', $vs);
- } elseif (Mb_strlen ($var, ' utf-8 ') = = = 1) {
- $start + = $Ints [$var];
- $var = ";
- Break
- }
- }
- return $start;
- } else {
- Return Intval ($var);
- }
- }
Copy Code
|