<?php
// Staring straight up into the sky ... oh my my
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord($number, $word1, $word2, $word5) {
/* DIY */
}
/*
Преобразует числа от 0 до 999 в текст. Параметр $isFemale равен нулю,
если мы считаем число для мужского рода (один рубль),
и 1 — для женского (одна тысяча)
*/
function smallNumberToText($number, $isFemale) {
$text = '';
0 => 'ноль', 10 => 'десять', 100 => 'сто',
1 => 'один', 11 => 'одиннадцать', 20 => 'двадцать', 200 => 'двести',
2 => 'два', 12 => 'двенадцать', 30 => 'тридцать', 300 => 'триста',
3 => 'три', 13 => 'тринадцать', 40 => 'сорок', 400 => 'четыреста',
4 => 'четыре', 14 => 'четырнадцать', 50 => 'пятьдесят', 500 => 'пятьсот',
5 => 'пять', 15 => 'пятнадцать', 60 => 'шестьдесят', 600 => 'шестьсот',
6 => 'шесть', 16 => 'шестнадцать', 70 => 'семьдесят', 700 => 'семьсот',
7 => 'семь', 17 => 'семнадцать', 80 => 'восемьдесят', 800 => 'восемьсот',
8 => 'восемь', 18 => 'восемнадцать', 90 => 'девяносто', 900 => 'девятьсот',
9 => 'девять', 19 => 'девятнадцать'
);
1 => 'одна', 2 => 'две'
);
if ($number < 10) {
$number = $spelling[$number % 10];
return $number;
}
if ($number < 100) {
$number = $spelling[($number % 100) - ($number % 10)].$spelling[$number % 10];
return $number;
}
if ($number < 1000) {
$number = $spelling[$number - ($number % 100)].' '.$spelling[($number % 100) - ($number % 10)].' '.$spelling[$number % 10];
return $number;
}
}
function numberToText($number) {
$text = '';
if ($number == 0) {
return 'ноль (0) рублей';
}
if ($number < 1000) {
$textNumber = smallNumberToText ($number);
if (($number % 10 < 5) and ($number % 10 != 1)) {
return "$textNumber ($number) рубля";
}
if (($number % 10 > 5) and ($number % 10 < 10)) {
return "$textNumber ($number) рублей";
}
}
}
/* Вызовем функцию несколько раз */
$text1 = numberToText($number);
echo "На вашем счету {$text1}\n";
PD9waHAKCi8vIFN0YXJpbmcgc3R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fQstC+0YHQtdC80YzQtNC10YHRj9GCJywgICA4MDAgPT4gICfQstC+0YHQtdC80YzRgdC+0YInLAogICAgICAgIDggICA9PiAgJ9Cy0L7RgdC10LzRjCcsICAgICAgIDE4ICA9PiAgJ9Cy0L7RgdC10LzQvdCw0LTRhtCw0YLRjCcsICAgICA5MCAgPT4gICfQtNC10LLRj9C90L7RgdGC0L4nLCAgICAgOTAwID0+ICAn0LTQtdCy0Y/RgtGM0YHQvtGCJywKICAgICAgICA5ICAgPT4gICfQtNC10LLRj9GC0YwnLCAgICAgICAxOSAgPT4gICfQtNC10LLRj9GC0L3QsNC00YbQsNGC0YwnICAgIAogICAgKTsKICAgIAogICAgJGZlbWFsZVNwZWxsaW5nID0gYXJyYXkoCiAgICAgICAgMSAgID0+ICAn0L7QtNC90LAnLCAgICAgICAgMiAgID0+ICAn0LTQstC1JwogICAgKTsKICAgICAKICAgIGlmICgkbnVtYmVyIDwgMTApIHsKICAgIAkkbnVtYmVyID0gJHNwZWxsaW5nWyRudW1iZXIgJSAxMF07CiAgICAJcmV0dXJuICRudW1iZXI7Cgl9CiAgICBpZiAoJG51bWJlciA8IDEwMCkgewogICAgCSRudW1iZXIgPSAkc3BlbGxpbmdbKCRudW1iZXIgJSAxMDApIC0gKCRudW1iZXIgJSAxMCldLiRzcGVsbGluZ1skbnVtYmVyICUgMTBdOwogICAgcmV0dXJuICRudW1iZXI7CiAgICB9CiAgICBpZiAoJG51bWJlciA8IDEwMDApIHsKICAgIAkkbnVtYmVyID0gJHNwZWxsaW5nWyRudW1iZXIgIC0gKCRudW1iZXIgJSAxMDApXS4nICcuJHNwZWxsaW5nWygkbnVtYmVyICUgMTAwKSAtICgkbnVtYmVyICUgMTApXS4nICcuJHNwZWxsaW5nWyRudW1iZXIgJSAxMF07CiAgICByZXR1cm4gJG51bWJlcjsKICAgIH0KfQoKZnVuY3Rpb24gbnVtYmVyVG9UZXh0KCRudW1iZXIpIHsKCQogICAgJHRleHQgPSAnJzsKICAgIA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