php教程 中文大写数字 转成 数字代码
echo "
";<br> echo test('一十二亿七十一万五十一');<br> /*<br> create by piaofen <br> date: 2011-03-31<br> function: 中文大写数字转阿拉伯数字<br> */<br> function chtonum($str='')<br> {<br> $unit = array('亿'=>100000000,'万'=>10000,'千'=>1000,'仟'=>1000,'百'=>100,'十'=>10);<br> $num = array('一'=>1,'二'=>2,'三'=>3,'四'=>4,'五'=>5,'六'=>6,'七'=>7,'八'=>8,'九'=>9);<br> $str = str_replace(array_keys($num),$num,$str);<br> $result = array();<br> $number = '';<br> preg_match_all('/[0-9]千[0-9]百[0-9]十[0-9]|[0-9]百[0-9]十[0-9]|[0-9]十[0-9]|[0-9]/ism',$str,$pnum);<br> foreach($pnum[0] as $val){<br> $tmp = '';<br> for($i=0;$i<mb_strlen></mb_strlen> $s = mb_substr($val,$i,1,'utf-8');<br> if(!is_numeric($s)){<br> $k = $unit[$s];<br> if(strlen($tmp)>=strlen($k)){<br> preg_match('/([0-9]*)([0-9]{'.(strlen($k)-1).'})([0-9])/ism',$tmp,$n);<br> $tmp = ($n[1]+$n[3]).$n[2];<br> }else{<br> $tmp = $tmp * $k;<br> }<br> }else if($i==(mb_strlen($val,'utf-8')-1)){<br> $tmp += $s;<br> }else{<br> $tmp .= $s;<br> }<br> }<br> $nnum[] = $tmp;<br> }<br> $result = str_replace(array_keys($unit),';',str_replace($pnum[0],$nnum,$str));<br> foreach(explode(';',$result) as $val){<br> $number .= sprintf('%04d',$val);<br> }<br> return sprintf('%2u',$number);<br> }<br>Copy after login