集数翻译函数(250719原创)
将第99999集翻译成第九万九千九百九十九集,使用函数如下:
function jishufanyi($i) {
$i = intval($i);
if ($i > 99999) {return '数字不可大于99999';}
$result = wanwei($i) . qianwei($i) . baiwei($i) . shiwei($i) . gewei($i);
$result = str_replace('零零零', '零', $result);
$result = str_replace('零零', '零', $result);
$result = mb_substr($result, 0, 1) == '零' ? ltrim($result, '零') : $result;
$result = mb_substr($result, -1, 1) == '零' ? rtrim($result, '零') : $result;
$result = mb_substr($result, 0, 2) == '一十' ? mb_substr($result, 1) : $result;
return $result;
}
function wanwei($i) {
$i = intval(substr(intval($i),-5));
if ($i/10000 >= 1) {
$number = floor($i/10000);
$result = gewei($number).'万';
} else {
$result = '零';
}
return $result;
}
function qianwei($i) {
$i = intval(substr(intval($i),-4));
if ($i/1000 >= 1) {
$number = floor($i/1000);
$result = gewei($number).'千';
} else {
$result = '零';
}
return $result;
}
function baiwei($i) {
$i = intval(substr(intval($i),-3));
if ($i/100 >= 1) {
$number = floor($i/100);
$result = gewei($number).'百';
} else {
$result = '零';
}
return $result;
}
function shiwei($i) {
$i = intval(substr(intval($i),-2));
if ($i/10 >= 1) {
$number = floor($i/10);
$result = gewei($number).'十';
} else {
$result = '零';
}
return $result;
}
function gewei($i) {
$i = substr(intval($i),-1);
$shuzu[0] = '零';
$shuzu[1] = '一';
$shuzu[2] = '二';
$shuzu[3] = '三';
$shuzu[4] = '四';
$shuzu[5] = '五';
$shuzu[6] = '六';
$shuzu[7] = '七';
$shuzu[8] = '八';
$shuzu[9] = '九';
return $shuzu[$i];
}
//$num=1,提取个位数,$num=2,提取二位数,$num为几,就提取几位数
function tiquweishu($i, $num) {
return intval(substr(intval($i),-$num));
}发表评论