| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
function checkNatInt($str) { $map = array( '1' => '1','2' => '2','3' => '3','4' => '4','5' => '5','6' => '6','7' => '7','8' => '8','9' => '9', 'Yi' => '1','Er' => '2','San' => '3','Ta' => '4','Wo' => '5','Loan' => '6','Authorization' => '7','Authorization' => '8','Authorization' => '9', '0' => '0','Two' => '2', 'Authorization' => 'Kilo','Authorization' => 'Bai','Pick' => '10', 'Ten thousand' => 'Yi', ); $str = str_replace(array_keys($map), array_values($map), $str); $str = checkString($str, '/([\ D hundreds of millions] +)/U'); $func_c2i = function ($str, $plus = false) use(&$func_c2i) { if(false === $plus) { $plus = array('Yi' => 100000000,'Wan' => 10000,'Kilo' => 1000,'Bai' => 100,'10' => 10,); } $i = 0; if($plus) foreach($plus as $k => $v) { $i++; if(strpos($str, $k) !== false) { $ex = explode($k, $str, 2); $new_plus = array_slice($plus, $i, null, true); $l = $func_c2i($ex[0], $new_plus); $r = $func_c2i($ex[1], $new_plus); if($l == 0) $l = 1; return $l * $v + $r; } } return (int)$str; } return $func_c2i($str); } // From the uct php development framework, where the checkString function is as follows function checkString($var, $check = '', $default = '') { if (!is_string($var)) { if(is_numeric($var)) { $var = (string)$var; } else { return $default; } } if ($check) { return (preg_match($check, $var, $ret) ? $ret[1] : $default); } return $var;} |