<?php
// Staring straight up into the sky ... oh my my
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord($number) {
$last2Digits = $number % 100;
$word1 = "($number) рубль";
$word2 = "($number) рубля";
$word5 = "($number) рубль";
$end5 = '#^([1-9]?[05-9])$^(1[0-9])$#';
$end1 = '#^[02-9]?1$#';
$end2 = '#^[02-9]?[2-4]$#';
return $word5;
}
return $word1;
}
return $word2;
}
}
/*
Преобразует числа от 0 до 999 в текст. Параметр $isFemale равен нулю,
если мы считаем число для мужского рода (один рубль),
и 1 — для женского (одна тысяча)
*/
function smallNumberToText($number) {
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 => 'две'
);
$from1to900 = '#^[1-9][0?0?]$#';
$first = 0; $second = 0; $third = 0;
$res = "";
if ($number == 0){
return $spelling[$number];
}
return $spelling[$number];
}
elseif(($number >= 11)&&($number <= 19)){
return $spelling[$number];
}
$first = floor($number/10)*10; $second = $number - $first;
$res = $spelling[$first]." ".$spelling[$second];
return $res;
}
else{
$first = floor($number / 100)*100; $third = $number - ($first + $second);
if((($number - $first)>=11) && (($number-$first))<=19){
$second = $number - $first;
$res = $spelling[$first]." ".$spelling[$second];
}
else{
$second = floor(($number - $first)/10)*10; $third = $number - ($first + $second);
if(($first != 0)&&($second != 0)&&($third != 0)){
$res = $spelling[$first]." ".$spelling[$second]." ".$spelling[$third];
}
elseif($second == 0){
$res = $spelling[$first]." ".$spelling[$third];
}
elseif($third == 0){
$res = $spelling[$first]." ".$spelling[$second];
}
}
return $res;
}
}
function numberToText($number) {
$result = "";
if(preg_match('#^([0-9])|([0-9]){2}|([11-19])|([0-9]{3})$#', $number)){ return smallNumberToText($number);
}
elseif(($number >= 1000)&&($number <= 999999)){
$result = smallNumberToText
(floor($number/1000))." тыс ".smallNumberToText
($number - (floor($number/1000)*1000)); }
/* Вызовем функцию несколько раз */
$text1 = numberToText($amount1);
echo "На вашем счету {$text1}\n";
$text2 = numberToText($amount2);
echo "На вашем счету {$text2}\n";
$text3 = numberToText($amount3);
echo "На вашем счету {$text3}\n";
$text4 = numberToText($amount4);
echo "На вашем счету {$text4}\n";
PD9waHAKCi8vIFN0YXJpbmcgc3RyYWlnaHQgdXAgaW50byB0aGUgc2t5IC4uLiBvaCBteSBteQplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCgovKiDQktC+0LfQstGA0LDRidCw0LXRgiDRgdC+0L7RgtCy0LXRgtGB0YLQstGD0Y7RidGD0Y4g0YfQuNGB0LvRgyDRhNC+0YDQvNGDINGB0LvQvtCy0LA6IDEg0YDRg9Cx0LvRjCwgMiDRgNGD0LHQu9GPLCA1INGA0YPQsdC70LXQuSAqLwpmdW5jdGlvbiBpbmNsaW5lV29yZCgkbnVtYmVyKSB7CiAgICAgJGxhc3QyRGlnaXRzID0gJG51bWJlciAlIDEwMDsKICAgICAkd29yZDEgPSAiKCRudW1iZXIpINGA0YPQsdC70YwiOwogICAgICR3b3JkMiA9ICIoJG51bWJlcikg0YDRg9Cx0LvRjyI7CiAgICAgJHdvcmQ1ID0gIigkbnVtYmVyKSDRgNGD0LHQu9GMIjsKICAgICAkZW5kNSA9ICcjXihbMS05XT9bMDUtOV0pJF4oMVswLTldKSQjJzsKICAgICAkZW5kMSA9ICcjXlswMi05XT8xJCMnOwogICAgICRlbmQyID0gJyNeWzAyLTldP1syLTRdJCMnOwogICAgIGlmKHByZWdfbWF0Y2goJGVuZDUsICRsYXN0MkRpZ2l0cykpewogICAgIAlyZXR1cm4gJHdvcmQ1OwogICAgIH0KICAgICBlbHNlaWYocHJlZ19tYXRjaCgkZW5kMSwgJGxhc3QyRGlnaXRzKSl7CiAgICAgCXJldHVybiAkd29yZDE7CiAgICAgfQogICAgIGVsc2VpZihwcmVnX21hdGNoKCRlbmQyLCAkbGFzdDJEaWdpdHMpKXsKICAgICAJcmV0dXJuICR3b3JkMjsKICAgICB9Cn0KLyogCiAgICDQn9GA0LXQvtCx0YDQsNC30YPQtdGCINGH0LjRgdC70LAg0L7RgiAwINC00L4gOTk5INCyINGC0LXQutGB0YIuINCf0LDRgNCw0LzQtdGC0YAgJGlzRmVtYWxlINGA0LDQstC10L0g0L3Rg9C70Y4sIAogICAg0LXRgdC70Lgg0LzRiyDRgdGH0LjRgtCw0LXQvCDRh9C40YHQu9C+INC00LvRjyDQvNGD0LbRgdC60L7Qs9C+INGA0L7QtNCwICjQvtC00LjQvSDRgNGD0LHQu9GMKSwgCiAgICDQuCAxIOKAlCDQtNC70Y8g0LbQtdC90YHQutC+0LPQviAo0L7QtNC90LAg0YLRi9GB0Y/Rh9CwKSAKKi8KZnVuY3Rpb24gc21hbGxOdW1iZXJUb1RleHQoJG51bWJlcikgewoKICAgICRzcGVsbGluZyA9IGFycmF5KAogICAgICAgIDAgICA9PiAgJ9C90L7Qu9GMJywgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTAgID0+ICAn0LTQtdGB0Y/RgtGMJywgICAgICAgMTAwID0+ICAn0YHRgtC+JywKICAgICAgICAxICAgPT4gICfQvtC00LjQvScsICAgICAgICAgMTEgID0+ICAn0L7QtNC40L3QvdCw0LTRhtCw0YLRjCcsICAgICAgMjAgID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