获取中文字符串中的数字并转换成阿拉伯数字
<?php
function charN2intN($str, $solve_discrete = true)
{
$arr_char_unit = array('1一壹','2二贰两','3三叁','4四肆','5五伍','6六陆','7七柒','8八捌','9九玖');
$arr_char_digit = array('0零','十拾','百佰','千仟','万','亿');
$temp_arr_match_num = "1一壹2二贰两3三叁4四肆5五伍6六陆7七柒8八捌9九玖0零十拾百佰千仟万亿";
$temp_len = iconv_strlen($str,'utf-8');
$temp_ans = "";
$temp_start = false;
for($i = 0;$i < $temp_len;$i++)
{
$temp_char = mb_substr($str,$i,1,'utf-8');
if((stripos($temp_arr_match_num, $temp_char) > -1))
{
$temp_start = true;
$temp_ans .= $temp_char;
}
else if(!$solve_discrete && $temp_start)
{
break;
}
}
$str = $temp_ans;
$str_len = iconv_strlen($str,'utf-8');
$objs_code = "";
$objs = [];
for($i = 0;$i < $str_len;$i++)
{
$temp_char = mb_substr($str,$i,1,'utf-8');
$isNum = false;
for($index = 0 ; $index < count($arr_char_unit);$index++)
{
if((stripos($arr_char_unit[$index], $temp_char) > -1))
{
$objs_code .='u';
$objs[] = [
'type' => 'unit',
'value' => $index+1
];
$isNum = true;
break;
}
}
if($isNum){
continue;}
for($index = 0 ; $index < count($arr_char_digit);$index++)