<?php
0 => "миллион",
1 => "миллиона",
2 => "миллионов"
),
0 => "тысяча",
1 => "тысячи",
2 => "тысяч"
),
0 => "рубль",
1 => "рубля",
2 => "рублей"
)
);
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord($endingNumber, $end) {
if (($endingNumber % 100 >= 10) && ($endingNumber % 100 <= 19)) {
$endingNumber = $endingNumber % 100;
} else {
$endingNumber = $endingNumber % 10;
}
if ($endingNumber == 1){
$word = $end[0];
} elseif (($endingNumber >= 2) && ($endingNumber <= 4)) {
$word = $end[1];
} else {
$word = $end[2];
}
return $word;
}
function writeThousand($key, $discharge, $spelling) {
if (($discharge == 1) && ($key == 1)) {
return 'одна';
} elseif (($discharge == 2) && ($key == 1)) {
return 'две';
} else {
return $spelling[$discharge];
}
}
//разбивает число на миллионы, тысяча и сотни
function splitToParts($number) {
$hundred = $number % 1000;
$thousand = $number % 1000000 / 1000;
$thousand = floor($thousand);
$million = $number % 1000000000 / 1000000;
$million = floor ($million);
0 => $million,
1 => $thousand,
2 => $hundred
);
return $level;
}
//переводит числовое число в текстовое
function smallNumberToarrayOfWords($number, $end) {
0 => 'ноль',
1 => 'один',
2 => 'два',
3 => 'три',
4 => 'четыре',
5 => 'пять',
6 => 'шесть',
7 => 'семь',
8 => 'восемь',
9 => 'девять',
10 => 'десять',
11 => 'одиннадцать',
12 => 'двенадцать',
13 => 'тринадцать',
14 => 'четырнадцать',
15 => 'пятнадцать',
16 => 'шестнадцать',
17 => 'семнадцать',
18 => 'восемнадцать',
19 => 'девятнадцать',
20 => 'двадцать',
30 => 'тридцать',
40 => 'сорок',
50 => 'пятьдесят',
60 => 'шестьдесят',
70 => 'семьдесят',
80 => 'восемьдесят',
90 => 'девяносто',
100 => 'сто',
200 => 'двести',
300 => 'триста',
400 => 'четыреста',
500 => 'пятьсот',
600 => 'шестьсот',
700 => 'семьсот',
800 => 'восемьсот',
900 => 'девятьсот',
);
$level = splitToParts($number);
if ($number == 0) {
echo "На вашем счету ноль рублей";
}
$numberOfWord = -1;
foreach($level as $key => $discharge) {
if ($discharge == 0 && $key == 2) {
$numberOfWord++;
$arrayOfWords[$numberOfWord] = "рублей";
continue;
} elseif ($discharge == 0) {
continue;
}
$endingNumber = $discharge;
if (($discharge >= 100) && ($discharge <= 999)) {
$numberOfWord++;
$numberInArray = floor($discharge / 100) * 100; $arrayOfWords[$numberOfWord] = $spelling[$numberInArray];
$discharge = $discharge % 100;
}
if (($discharge >= 10) && ($discharge <= 19)) {
$numberOfWord++;
$numberInArray = $discharge;
$arrayOfWords[$numberOfWord] = $spelling[$numberInArray];
} elseif ($discharge != 0) {
if ($discharge <= 9 || $discharge % 10 == 0) {
$numberOfWord++;
$arrayOfWords[$numberOfWord] = writeThousand($key, $discharge, $spelling);
} else {
$numberOfWord++;
$numberInArray = floor($discharge / 10) * 10; $arrayOfWords[$numberOfWord] = $spelling[$numberInArray];
$discharge = $discharge % 10;
$numberOfWord++;
$arrayOfWords[$numberOfWord] = writeThousand($key, $discharge, $spelling);
}
} elseif ($key == 2 && $discharge == 0 && $number != 0) {
$numberOfWord++;
$arrayOfWords[$numberOfWord] = "рублей";
}
$numberOfWord++;
$word = inclineWord($endingNumber, $end[$key]);
$arrayOfWords[$numberOfWord] = $word;
}
$text = implode(" ", $arrayOfWords); return $text;
}
$number = smallNumberToarrayOfWords($number, $end);
echo "На вашем счету {$number}\n";
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiRlbmQgPSBhcnJheSgKCTAgPT4gYXJyYXkoCgkJMCA9PiAi0LzQuNC70LvQuNC+0L0iLAoJCTEgPT4gItC80LjQu9C70LjQvtC90LAiLAoJCTIgPT4gItC80LjQu9C70LjQvtC90L7QsiIKCSksCgkxID0+IGFycmF5KAoJCTAgPT4gItGC0YvRgdGP0YfQsCIsCgkJMSA9PiAi0YLRi9GB0Y/Rh9C4IiwKCQkyID0+ICL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V0dXJuICfQtNCy0LUnOwkJCQkJCgl9IGVsc2UgewoJCXJldHVybiAkc3BlbGxpbmdbJGRpc2NoYXJnZV07Cgl9Cn0KIAovL9GA0LDQt9Cx0LjQstCw0LXRgiDRh9C40YHQu9C+INC90LAg0LzQuNC70LvQuNC+0L3Riywg0YLRi9GB0Y/Rh9CwINC4INGB0L7RgtC90LgKZnVuY3Rpb24gc3BsaXRUb1BhcnRzKCRudW1iZXIpIHsKCQoJJGh1bmRyZWQgPSAkbnVtYmVyICUgMTAwMDsKICAgCiAgICAKICAgICR0aG91c2FuZCA9ICRudW1iZXIgJSAxMDAwMDAwIC8gMTAwMDsKICAgICR0aG91c2FuZCA9IGZsb29yKCR0aG91c2FuZCk7CiAKICAgICRtaWxsaW9uID0gJG51bWJlciAlIDEwMDAwMDAwMDAgLyAxMDAwMDAwOwoJJG1pbGxpb24gPSBmbG9vciAoJG1pbGxpb24pOwogCgkkbGV2ZWwgPSBhcnJheSgKCSAgICAwID0+ICRtaWxsaW9uLAoJCTEgPT4gJHRob3VzYW5kLAoJCTIgPT4gJGh1bmRyZWQKCSk7CgkKCXJldHVybiAkbGV2ZWw7Cn0KIAovL9C/0LXRgNC10LLQvtC00LjRgiDRh9C40YHQu9C+0LLQvtC1INGH0LjRgdC70L4g0LIg0YLQtdC60YHRgtC+0LLQvtC1IApmdW5jdGlvbiBzbWFsbE51bWJlclRvYXJyYXlPZldvcmRzKCRudW1iZXIsICRlbmQpIHsKCQogICAgJHNwZWxsaW5nID0gYXJyYXkoCiAgICAgICAgMCAgID0+ICAn0L3QvtC70YwnLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAxICAgPT4gICfQvtC00LjQvScsICAgICAgICAgICAgICAgICAgIAogICAgICAgIDIgICA9PiAgJ9C00LLQsCcsICAgICAgICAgICAgICAgICAgIAogICAgICAgIDMgICA9PiAgJ9GC0YDQuCcsICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgNCAgID0+ICAn0YfQtdGC0YvRgNC1JywgICAgICAgICAgICAgIAogICAgICAgIDUgICA9PiAgJ9C/0Y/RgtGMJywgICAgICAgICAgICAgICAgCiAgICAgICAgNiAgID0+ICAn0YjQtdGB0YLRjCcsICAgICAgICAgICAgICAgICAgIAogICAgICAgIDcgICA9PiAgJ9GB0LXQvNGMJywgICAgICAgICAgICAgICAgIAogICAgICAgIDggICA9PiAgJ9Cy0L7RgdC10LzRjCcsICAgICAgICAgICAgCiAgICAgICAgOSAgID0+ICAn0LTQtdCy0Y/RgtGMJywKICAgICAgICAxMCAgPT4gICfQtNC10YHRj9GC0YwnLCAJCiAgICAgICAgMTEgID0+ICAn0L7QtNC40L3QvdCw0LTRhtCw0YLRjCcsCQogICAgICAgIDEyICA9PiAgJ9C00LLQtdC90LDQtNGG0LDRgtGMJywgIAogICAgICAgIDEzICA9PiAgJ9GC0YDQuNC90LDQtNGG0LDRgtGMJywgCiAgICAgICAgMTQgID0+ICAn0YfQtdGC0YvRgNC90LDQtNGG0LDRgtGMJywgIAogICAgICAgIDE1ICA9PiAgJ9C/0Y/RgtC90LDQtNGG0LDRgtGMJywgICAKICAgICAgICAxNiAgPT4gICfRiNC10YHRgtC90LDQtNGG0LDRgtGMJywgCiAgICAgICAgMTcgID0+ICAn0YHQtdC80L3QsNC00YbQsNGC0YwnLCAgCiAgICAgICAgMTggID0+ICAn0LLQvtGB0LXQvNC90LDQtNGG0LDRgtGMJywgICAgCgkgICAgMTkgID0+ICAn0LTQtdCy0Y/RgtC90LDQtNGG0LDRgtGMJywgIAogICAgICAgIDIwICA9PiAgJ9C00LLQsNC00YbQsNGC0YwnLCAJCiAgICAgICAgMzAgID0+ICAn0YLRgNC40LTRhtCw0YLRjCcsCiAgICAgICAgNDAgID0+ICAn0YHQvtGA0L7QuicsCiAgICAgICAgNTAgID0+ICAn0L/Rj9GC0YzQtNC10YHRj9GCJywKICAgICAgICA2MCAgPT4gICfRiNC10YHRgtGM0LTQtdGB0Y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