Skip to content

Instantly share code, notes, and snippets.

@hideshi
Created April 22, 2014 13:45
Show Gist options
  • Save hideshi/11179826 to your computer and use it in GitHub Desktop.
Save hideshi/11179826 to your computer and use it in GitHub Desktop.
<?php
function convert($number) {
$array1 = array('兆', '億', '万', '千', '百', '十');
$array2 = array('', '一', '二', '三', '四', '五', '六', '七', '八', '九');
$chou = (int)($number / 1000000000000);
$rest = $number % 1000000000000;
$oku = (int)($rest / 100000000);
$rest = $rest % 100000000;
$man = (int)($rest / 10000);
$rest = $rest % 10000;
$sen = (int)($rest / 1000);
$rest = $rest % 1000;
$hyaku = (int)($rest / 100);
$rest = $rest % 100;
$juu = (int)($rest / 10);
$ichi = $rest % 10;
if(0 < $chou && $chou < 10) {
$result = $result.$array2[$chou].$array1[0];
} elseif($chou != 0) {
$result = $result.convert($chou).$array1[0];
}
if(0 < $oku && $oku < 10) {
$result = $result.$array2[$oku].$array1[1];
} elseif($oku != 0) {
$result = $result.convert($oku).$array1[1];
}
if(0 < $man && $man < 10) {
$result = $result.$array2[$man].$array1[2];
} elseif($man != 0) {
$result = $result.convert($man).$array1[2];
}
if(0 < $sen && $sen < 10) {
$result = $result.$array2[$sen].$array1[3];
}
if(1 < $hyaku && $hyaku < 10) {
$result = $result.$array2[$hyaku].$array1[4];
} elseif($hyaku == 1) {
$result = $result.$array1[4];
}
if(1 < $juu && $juu < 10) {
$result = $result.$array2[$juu].$array1[5];
} elseif($juu == 1) {
$result = $result.$array1[5];
}
if(0 < $ichi && $ichi < 10) {
$result = $result.$array2[$ichi];
}
return $result;
}
echo convert(1234567890123456)."\n";
echo convert(123456789012)."\n";
echo convert(12345678)."\n";
echo convert(1234)."\n";
echo convert(123)."\n";
echo convert(12)."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment