<?php
0 => "миллион",
1 => "миллиона",
2 => "миллионов"
),
0 => "тысяча",
1 => "тысячи",
2 => "тысяч"
),
0 => "рубль",
1 => "рубля",
2 => "рублей"
)
);
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord($latterFigure, $end) {
if ($latterFigure == 1){
$word = $end[0];
} elseif (($latterFigure >= 2) && ($latterFigure <= 4)) {
$word = $end[1];
} else {
$word = $end[2];
}
return $word;
}
function writeThousand($declension, $discharge, $spelling) {
if (($discharge == 1) && ($declension == 1)) {
return 'одна';
} elseif (($discharge == 2) && ($declension == 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 smallNumberToText($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);
$text = "";
foreach($level as $declension => $discharge) {
if ($number == 0) {
$text = " ноль рублей";
}
if ($discharge != 0) {
$aboveZero = true;
}
//сохранение последней цифры для возвращения слова
if (($discharge % 100 >= 10) && ($discharge % 100 <= 19)) {
$latterFigure = $discharge % 100;
} else {
$latterFigure = $discharge % 10;
}
if (($discharge >= 100) && ($discharge <= 999)) {
$numberInArray = floor($discharge / 100) * 100; $text = $text.' '.$spelling[$numberInArray];
$discharge = $discharge % 100;
}
if (($discharge >= 10) && ($discharge <= 19)) {
$numberInArray = $discharge;
$text = $text.' '.$spelling[$numberInArray];
} elseif ($discharge != 0) {
if ($discharge <= 9 || $discharge % 10 == 0) {
$i = 1;
} else {
$i = 2;
}
switch ($i) {
case 1:
$text = $text.' '.writeThousand($declension, $discharge, $spelling);
break;
case 2:
$numberInArray = floor($discharge / 10) * 10; $text = $text.' '.$spelling[$numberInArray];
$discharge = $discharge % 10;
$text = $text.' '.writeThousand($declension, $discharge, $spelling);
}
} elseif ($declension == 2 && $discharge == 0 && $number != 0) {
$text = $text.' рублей';
}
if ($aboveZero == true) {
$word = inclineWord($latterFigure, $end[$declension]);
$text = $text.' '.$word;
$aboveZero = false;
}
}
return $text;
}
$number = smallNumberToText($number, $end);
echo "На вашем счету{$number}\n";
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiRlbmQgPSBhcnJheSgKCTAgPT4gYXJyYXkoCgkJMCA9PiAi0LzQuNC70LvQuNC+0L0iLAoJCTEgPT4gItC80LjQu9C70LjQvtC90LAiLAoJCTIgPT4gItC80LjQu9C70LjQvtC90L7QsiIKCSksCgkxID0+IGFycmF5KAoJCTAgPT4gItGC0YvRgdGP0YfQsCIsCgkJMSA9PiAi0YLRi9GB0Y/Rh9C4IiwKCQkyID0+ICLRgtGL0YHRj9GHIgoJKSwKCTIgPT4gYXJyYXkoCgkJMCA9PiAi0YDRg9Cx0LvRjCIsCgkJMSA9PiAi0YDRg9Cx0LvRjyIsCgkJMiA9PiAi0YDRg9Cx0LvQtdC5IgoJKQopOwoKLyog0JLQvtC30LLRgNCw0YnQsNC10YIg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TAwMDsKICAgICR0aG91c2FuZCA9IGZsb29yKCR0aG91c2FuZCk7CiAKICAgICRtaWxsaW9uID0gJG51bWJlciAlIDEwMDAwMDAwMDAgLyAxMDAwMDAwOwoJJG1pbGxpb24gPSBmbG9vciAoJG1pbGxpb24pOwogCgkkbGV2ZWwgPSBhcnJheSgKCSAgICAwID0+ICRtaWxsaW9uLAoJCTEgPT4gJHRob3VzYW5kLAoJCTIgPT4gJGh1bmRyZWQKCSk7CgkKCXJldHVybiAkbGV2ZWw7Cn0KIAovL9C/0LXRgNC10LLQvtC00LjRgiDRh9C40YHQu9C+0LLQvtC1INGH0LjRgdC70L4g0LIg0YLQtdC60YHRgtC+0LLQvtC1IApmdW5jdGlvbiBzbWFsbE51bWJlclRvVGV4dCgkbnVtYmVyLCAkZW5kKSB7CgkKICAgICRzcGVsbGluZyA9IGFycmF5KAogICAgICAgIDAgICA9PiAgJ9C90L7Qu9GMJywgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgMSAgID0+ICAn0L7QtNC40L0nLCAgICAgICAgICAgICAgICAgICAKICAgICAgICAyICAgPT4gICfQtNCy0LAnLCAgICAgICAgICAgICAgICAgICAKICAgICAgICAzICAgPT4gICfRgtGA0LgnLCAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgIDQgICA9PiAgJ9GH0LXRgtGL0YDQtScsICAgICAgICAgICAgICAKICAgICAgICA1ICAgPT4gICfQv9GP0YLRjCcsICAgICAgICAgICAgICAgIAogICAgICAgIDYgICA9PiAgJ9GI0LXRgdGC0YwnLCAgICAgICAgICAgICAgICAgICAKICAgICAgICA3ICAgPT4gICfRgdC10LzRjCcsICAgICAgICAgICAgICAgICAKICAgICAgICA4ICAgPT4gICfQstC+0YHQtdC80YwnLCAgICAgICAgICAgIAogICAgICAgIDkgICA9PiAgJ9C00LXQstGP0YLRjCcsCiAgICAgICAgMTAgID0+ICAn0LTQtdGB0Y/RgtGMJywgCQogICAgICAgI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