[共享源码]数字转换成中文大写
$CHDIGIT= array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
$CHUNIT1 = array('','万','亿');
$CHUNIT2 = array('','拾','佰','千');
function ChineseSpellNumber($number)
{
$strNumber = '';
global $CHDIGIT, $CHUNIT1;
$j = 0;
while( !empty($number) )
{
$thousands = substr($number, -4);
$tmp = trim(GetThousands((int)$thousands));
if ($j<sizeof($CHUNIT1))
{
$chunit = $CHUNIT1[$j];
} else {
$chunit = '';
for ($k = 0; $k <= $j - sizeof($CHUNIT1); $k++)
{
$chunit .= $CHUNIT1[1];
}
$chunit .= $CHUNIT1[2];
}
$chunit = "<font color='#0000FF'>$chunit</font>";
$strNumber = $tmp.(empty($tmp)? '' : $chunit).$strNumber;
$number = substr($number, 0, -4);
$j ++;
}
$strNumber = trim($strNumber, $CHDIGIT[0]);
return $strNumber;
}
function GetThousands($thousands)
{
global $CHDIGIT, $CHUNIT2;
$n = (int)$thousands;
$j = 0;
while ($n > 0)
{
$mod = $n % 10;
$n = floor($n /10);
$tmp = $CHDIGIT[$mod]. ($mod==0?'':$CHUNIT2[$j]);
$result = $tmp . $result;
$j ++;
}
if (strlen($thousands) < 4) $result = $CHDIGIT[0].$result;
$result = preg_replace('/('.$CHDIGIT[0].')+/', '$1', $result);
$result = preg_replace('/('.$CHDIGIT[0].')+$/', '', $result);
return $result;
}
测试地址:http://www.dictworld.com/search.php?q=1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890&lang=cn