<?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 > 9) and ($number < 20)) {
$number = $spelling[$number % 100];
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) {
if ($number == 0) {
return 'ноль (0) рублей';
}
$a=$number % 10;
$b=$number % 100;
if ($number < 1000) {
$textNumber = smallNumberToText ($number);
if ($a == 0) {
return "$textNumber ($number) рублей";
}
if ($b == 0 ) {
return "$textNumber ($number) рублей";
}
if (($a < 5) and ($a != 1) and ($a != 0)) {
return "$textNumber ($number) рубля";
}
if (($a >= 5) and ($a < 10)) {
return "$textNumber ($number) рублей";
}
if ($a == 1) {
return "$textNumber ($number) рубль";
}
if (($b >= 10) and ($b < 20)){
return "$textNumber ($number) рублей";
}
}
}
/* Вызовем функцию несколько раз */
$number = 302;
$text1 = numberToText($number);
echo "На вашем счету {$text1}\n";
echo $number;
PD9waHAKCi8vIFN0YXJpbmcgc3RyYWlnaHQgdXAgaW50byB0aGUgc2t5IC4uLiBvaCBteSBteQplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCgovKiDQktC+0LfQstGA0LDRidCw0LXRgiDRgdC+0L7RgtCy0LXRgtGB0YLQstGD0Y7RidGD0Y4g0YfQuNGB0LvRgyDRhNC+0YDQvNGDINGB0LvQvtCy0LA6IDEg0YDRg9Cx0LvRjCwgMiDRgNGD0LHQu9GPLCA1INGA0YPQsdC70LXQuSAqLwpmdW5jdGlvbiBpbmNsaW5lV29yZCgkbnVtYmVyLCAkd29yZDEsICR3b3JkMiwgJHdvcmQ1KSB7CiAgICAvKiBESVkgKi8KfQoKLyogCiAgICDQn9GA0LXQvtCx0YDQsNC30YPQtdGCINGH0LjRgdC70LAg0L7RgiAwINC00L4gOTk5INCyINGC0LXQutGB0YIuINCf0LDRgNCw0LzQtdGC0YAgJGlzRmVtYWxlINGA0LDQstC10L0g0L3Rg9C70Y4sIAogICAg0LXRgdC70Lgg0LzRiyDRgdGH0LjRgtCw0LXQvCDRh9C40YHQu9C+INC00LvRjyDQvNGD0LbRgdC60L7Qs9C+INGA0L7QtNCwICjQvtC00LjQvSDRgNGD0LHQu9GMKSwgCiAgICDQuCAxIOKAlCDQtNC70Y8g0LbQtdC90YHQutC+0LPQviAo0L7QtNC90LAg0YLRi9GB0Y/Rh9CwKSAKKi8KZnVuY3Rpb24gc21hbGxOdW1iZXJUb1RleHQoJG51bWJlciwgJGlzRmVtYWxlKSB7CgoJJHRleHQgPSAnJzsKICAgICRzcGVsbGluZyA9IGFycmF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YLRjCcsICAgICAgNzAgID0+ICAn0YHQtdC80YzQtNC10YHRj9GCJywgICAgNzAwID0+ICAn0YHQtdC80YzRgdC+0YInLCAgICAKICAgICAgICA3ICAgPT4gICfRgdC10LzRjCcsICAgICAgICAgMTcgID0+ICAn0YHQtdC80L3QsNC00YbQsNGC0YwnLCAgICAgICA4MCAgPT4gICfQstC+0YHQtdC80YzQtNC10YHRj9GCJywgICA4MDAgPT4gICfQstC+0YHQtdC80YzRgdC+0YInLAogICAgICAgIDggICA9PiAgJ9Cy0L7RgdC10LzRjCcsICAgICAgIDE4ICA9PiAgJ9Cy0L7RgdC10LzQvdCw0LTRhtCw0YLRjCcsICAgICA5MCAgPT4gICfQtNC10LLRj9C90L7RgdGC0L4nLCAgICAgOTAwID0+ICAn0LTQtdCy0Y/RgtGM0YHQvtGCJywKICAgICAgICA5ICAgPT4gICfQtNC10LLRj9GC0YwnLCAgICAgICAxOSAgPT4gICfQtNC10LLRj9GC0L3QsNC00YbQsNGC0YwnICAgIAogICAgKTsKICAgIAogICAgJGZlbWFsZVNwZWxsaW5nID0gYXJyYXkoCiAgICAgICAgMSAgID0+ICAn0L7QtNC90LAnLCAgICAgICAgMiAgID0+ICAn0LTQstC1JwogICAgKTsKICAgICAKICAgIGlmICgkbnVtYmVyIDwgMTApIHsKICAgIAkkbnVtYmVyID0gJHNwZWxsaW5nWyRudW1iZXIgJSAxMF07CiAgICAJcmV0dXJuICRudW1iZXI7Cgl9CgkgaWYgKCgkbnVtYmVyID4gOSkgYW5kICgkbnVtYmVyIDwgMjApKSB7CiAgICAJJG51bWJlciA9ICRzcGVsbGluZ1skbnVtYmVyICUgMTAwXTsKICAgIAlyZXR1cm4gJG51bWJlcjsKCX0KICAgIGlmICgkbnVtYmVyIDwgMTAwKSB7CiAgICAJJG51bWJlciA9ICRzcGVsbGluZ1soJG51bWJlciAlIDEwMCkgLSAoJG51bWJlciAlIDEwKV0uJHNwZWxsaW5nWyRudW1iZXIgJSAxMF07CiAgICByZ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