<?php
// Staring straight up into the sky ... oh my my
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord( $number ) {
if ( ( $number % 100 >= 10 ) && ( $number % 100 <= 20 ) ) {
$number = " рублей" ;
}
elseif ( ( $number % 10 == 0 ) || ( $number % 10 >= 5 ) ) {
$number = " рублей" ;
}
elseif ( ( $number % 10 >= 2 ) && ( $number % 10 <= 4 ) ) {
$number = " рубля" ;
}
else {
$number = " рубль" ;
}
return $number ;
}
/* Разбивает число на разряды (по три цифры) и посылает их обрабатывать в функцию smallNumberToText*/
function splitNumberToText( $number ) {
$million = floor ( $number / 1000000 ) ; if ( $million != 0 ) {
$word = smallNumberToText( $million , 1 ) ;
if ( ( $million % 10 == 1 ) && ( $million != 11 ) ) {
$word = $word . " миллион " ;
}
elseif ( ( $million % 10 >= 2 ) && ( $million % 10 <= 4 ) ) {
$word = $word . " миллиона " ;
}
else {
$word = $word . " миллионов " ;
}
}
$x = $number % 1000000 ;
$thousand = floor ( $x / 1000 ) ; if ( $thousand != 0 ) {
$word = $word . smallNumberToText( $thousand , 2 ) ;
if ( ( $thousand % 10 == 1 ) && ( $thousand != 11 ) ) {
$word = $word . " тысяча " ;
}
elseif ( ( $thousand % 10 >= 2 ) && ( $thousand % 10 <= 5 ) ) {
$word = $word . " тысячи " ;
}
else {
$word = $word . " тысяч " ;
}
}
$hundred = $number % 1000 ;
$word = $word . smallNumberToText( $hundred , 1 ) ;
return $word ;
}
/*
Преобразует числа от 0 до 999 в текст. Параметр $isFemale равен нулю,
если мы считаем число для мужского рода (один рубль),
и 1 — для женского (одна тысяча)
*/
function smallNumberToText( $number , $isFemale ) {
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 => 'девятнадцать'
) ;
if ( $isFemale == 2 ) {
$spelling [ 1 ] = 'одна' ;
$spelling [ 2 ] = 'две' ;
}
$word = '' ;
if ( $number == 0 ) {
$word = $spelling [ $number ] ;
return $word ;
}
$firstDigit = floor ( $number / 100 ) ; if ( ( $firstDigit != 0 ) && ( $number >= 100 ) ) {
$firstDigit = $firstDigit * 100 ;
$word = $word . $spelling [ $firstDigit ] ;
}
$x = $number % 100 ;
if ( ( $x >= 11 ) && ( $x <= 19 ) ) {
$word = $word . ' ' . $spelling [ $x ] ;
}
else {
$secondDigit = floor ( $x / 10 ) ; if ( ( $secondDigit != 0 ) && ( $number >= 10 ) ) {
$secondDigit = $secondDigit * 10 ;
$word = $word . ' ' . $spelling [ $secondDigit ] ;
}
$thirdDigit = $number % 10 ;
if ( $thirdDigit != 0 ) {
$word = $word . ' ' . $spelling [ $thirdDigit ] ;
}
}
return $word ;
}
function numberToText( $number ) {
$number = splitNumberToText( $number ) . ' ' . '(' . $number . ')' . inclineWord( $number ) ;
return $number ;
}
$text1 = numberToText( $amount1 ) ;
echo "На вашем счету{$text1} \n " ;
$text2 = numberToText( $amount2 ) ;
echo "На вашем счету{$text2} \n " ;
$text3 = numberToText( $amount3 ) ;
echo "На вашем счету{$text3} \n " ;
$text4 = numberToText( $amount4 ) ;
echo "На вашем счету{$text4} \n " ;
PD9waHAKICAgIC8vIFN0YXJpbmcgc3RyYWlnaHQgdXAgaW50byB0aGUgc2t5IC4uLiBvaCBteSBteQogICAgZXJyb3JfcmVwb3J0aW5nKC0xKTsKICAgIG1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwogICAgCiAgICAvKiDQktC+0LfQstGA0LDRidCw0LXRgiDRgdC+0L7RgtCy0LXRgtGB0YLQstGD0Y7RidGD0Y4g0YfQuNGB0LvRgyDRhNC+0YDQvNGDINGB0LvQvtCy0LA6IDEg0YDRg9Cx0LvRjCwgMiDRgNGD0LHQu9GPLCA1INGA0YPQsdC70LXQuSAqLwogICAgZnVuY3Rpb24gaW5jbGluZVdvcmQoJG51bWJlcikgewogICAgICAgIGlmICgoJG51bWJlciAlIDEwMCA+PSAxMCkgJiYgKCRudW1iZXIgJSAxMDAgPD0gMjApKSB7CiAgICAgICAgICAgICRudW1iZXIgPSAiINGA0YPQsdC70LXQuSI7CiAgICAgICAgfQogICAgICAgIGVsc2VpZiAoKCRudW1iZXIgJSAxMCA9PSAwKSB8fCAoJG51bWJlciAlIDEwID49IDUpKSB7CiAgICAgICAgIAkkbnVtYmVyID0gIiDRgNGD0LHQu9C10LkiOwogICAgICAgIH0KICAgICAgICBlbHNlaWYgKCgkbnVtYmVyICUgMTAgPj0gMikgJiYgKCRudW1iZXIgJSAxMCA8PSA0KSkgewogICAgICAgICAgCSRudW1iZXIgPSAiINGA0YPQsdC70Y8iOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgCSRudW1iZXIgPSAiINGA0YPQsdC70YwiOwogICAgICAgIH0KICAgICAgICByZXR1cm4gJG51bWJlcjsKICAgIH0KICAgICAgICAKICAgIC8qINCg0LDQt9Cx0LjQstCw0LXRgiDRh9C40YHQu9C+INC90LAg0YDQsNC30YDRj9C00YsgKNC/0L4g0YLRgNC4INGG0LjRhNGA0YspINC4INC/0L7RgdGL0LvQsNC10YIg0LjRhSDQvtCx0YDQsNCx0LDRgtGL0LLQsNGC0Ywg0LIg0YTRg9C90LrRhtC40Y4gc21hbGxOdW1iZXJUb1RleHQqLwogICAgZnVuY3Rpb24gc3BsaXROdW1iZXJUb1RleHQoJG51bWJlcikgewogICAgICAgICRtaWxsaW9uID0gZmxvb3IoJG51bWJlciAvIDEwMDAwMDApOwogICAgICAgIGlmICgkbWlsbGlvbiAhPSAwKSB7CiAgICAgICAgICAgICR3b3JkID0gc21hbGxOdW1iZXJUb1RleHQoJG1pbGxpb24sIDEpOwogICAgICAgICAgICBpZiAoKCRtaWxsaW9uICUgMTAgPT0gMSkgJiYgKCRtaWxsaW9uICE9IDExKSkgewogICAgICAgICAgICAgICAgJHdvcmQgPSAkd29yZCAuICIg0LzQuNC70LvQuNC+0L0gIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlaWYgKCgkbWlsbGlvbiAlIDEwID49IDIpICYmICgkbWlsbGlvbiAlIDEwIDw9IDQpKSB7CiAgICAgICAgICAgICAgICAkd29yZCA9ICR3b3JkIC4gIiDQvNC40LvQu9C40L7QvdCwICI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICAkd29yZCA9ICR3b3JkIC4gIiDQvNC40LvQu9C40L7QvdC+0LIgIjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAkeCA9ICRudW1iZXIgJSAxMDAwMDAwOwogICAgICAgICR0aG91c2FuZCA9IGZsb29yKCR4IC8gMTAwMCk7CiAgICAgICAgaWYgKCR0aG91c2FuZCAhPSAwKSB7CiAgICAgICAgICAgICR3b3JkID0gJHdvcmQgLiBzbWFsbE51bWJlclRvVGV4dCgkdGhvdXNhbmQsIDIpOwogICAgICAgICAgICBpZiAoKCR0aG91c2FuZCAlIDEwID09IDEpICYmICgkdGhvdXNhbmQgIT0gMTEpKSB7CiAgICAgICAgICAgICAgICAkd29yZCA9ICR3b3JkIC4gIiDRgtGL0YHRj9GH0LAgIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlaWYgKCgkdGhvdXNhbmQgJSAxMCA+PSAyKSAmJiAoJHRob3VzYW5kICUgMTAgPD0gNSkpIHsKICAgICAgICAgICAgICAgICR3b3JkID0gJHdvcmQgLiAiINGC0YvRgdGP0YfQuCAiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgJHdvcmQgPSAkd29yZCAuICIg0YLRi9GB0Y/RhyAiOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICRodW5kcmVkID0gJG51bWJlciAlIDEwMDA7CiAgICAgICAgJHdvcmQgPSAkd29yZCAuIHNtYWxsTnVtYmVyVG9UZXh0KCRodW5kcmVkLCAxKTsKICAgICAgICByZXR1cm4gJHdvcmQ7Cgl9CiAgICAvKiAKICAgINCf0YDQtdC+0LHRgNCw0LfRg9C10YIg0YfQuNGB0LvQsCDQvtGCIDAg0LTQviA5OTkg0LIg0YLQtdC60YHRgi4g0J/QsNGA0LDQvNC10YLRgCAkaXNGZW1hbGUg0YDQsNCy0LXQvSDQvdGD0LvRjiwgCiAgICDQtdGB0LvQuCDQvNGLINGB0YfQuNGC0LDQtdC8INGH0LjRgdC70L4g0LTQu9GPINC80YPQttGB0LrQvtCz0L4g0YDQvtC00LAgKNC+0LTQuNC9INGA0YPQsdC70YwpLCAKICAgINC4IDEg4oCUINC00LvRjyDQttC10L3RgdC60L7Qs9C+ICjQvtC00L3QsCDRgtGL0YHRj9GH0LApIAogICAgKi8KICAgIGZ1bmN0aW9uIHNtYWxsTnVtYmVyVG9UZXh0KCRudW1iZXIsICRpc0ZlbWFsZSkgewogICAgICAgICRzcGVsbGluZyA9IGFycmF5KAogICAgICAgIDAgICA9PiAgJ9C90L7Qu9GMJywgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTAgID0+ICAn0LTQtdGB0Y/RgtGMJywgICAgICAgMTAwID0+ICAn0YHRgtC+JywKICAgICAgICAxICAgPT4gICfQvtC00LjQvScsICAgICAgICAgMTEgID0+ICAn0L7QtNC40L3QvdCw0LTRhtCw0YLRjCcsICAgICAgMjAg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T4gICfQstC+0YHQtdC80YzRgdC+0YInLAogICAgICAgIDggICA9PiAgJ9Cy0L7RgdC10LzRjCcsICAgICAgIDE4ICA9PiAgJ9Cy0L7RgdC10LzQvdCw0LTRhtCw0YLRjCcsICAgICA5MCAgPT4gICfQtNC10LLRj9C90L7RgdGC0L4nLCAgICAgOTAwID0+ICAn0LTQtdCy0Y/RgtGM0YHQvtGCJywKICAgICAgICA5ICAgPT4gICfQtNC10LLRj9GC0YwnLCAgICAgICAxOSAgPT4gICfQtNC10LLRj9GC0L3QsNC00YbQsNGC0YwnICAgIAogICAgICAgICk7CiAgICAgICAgCiAgICBpZiAoJGlzRmVtYWxlID09IDIpIHsKICAgICAgICAkc3BlbGxpbmdbMV0gPSAn0L7QtNC90LAnOwogICAgICAgICRzcGVsbGluZ1syXSA9ICfQtNCy0LUnOwogICAgfQogICAgICAgIAogICAgJHdvcmQgPSAnJzsgCiAgICAKICAgIGlmICgkbnVtYmVyID09IDApIHsKICAgICAJJHdvcmQgPSAkc3BlbGxpbmdbJG51bWJlcl07CiAgICAgIAlyZXR1cm4gJHdvcmQ7CiAgICB9CiAgICAKICAgICRmaXJzdERpZ2l0ID0gZmxvb3IoJG51bWJlciAvIDEwMCk7CiAgICBpZiAoKCRmaXJzdERpZ2l0ICE9IDApICYmICgkbnVtYmVyID49IDEwMCkpIHsKICAgICAgICAkZmlyc3REaWdpdCA9ICRmaXJzdERpZ2l0ICogMTAwOwogICAgICAgICR3b3JkID0gJHdvcmQgLiAkc3BlbGxpbmdbJGZpcnN0RGlnaXRdOwogICAgfQogICAgCiAgICAkeCA9ICRudW1iZXIgJSAxMDA7CiAgICBpZiAoKCR4ID49IDExKSAmJiAoJHggPD0gMTkpKSB7CiAgICAgICAgJHdvcmQgPSAkd29yZCAuICcgJyAuICRzcGVsbGluZ1skeF07IAogICAgfQogICAgZWxzZSB7CiAgICAgICAgJHNlY29uZERpZ2l0ID0gZmxvb3IoJHggLyAxMCk7CiAgICAgICAgaWYgKCgkc2Vjb25kRGlnaXQgIT0gMCkgJiYgKCRudW1iZXIgPj0gMTApKXsKICAgICAgCSRzZWNvbmREaWdpdCA9ICRzZWNvbmREaWdpdCAqIDEwOwogICAgICAgICR3b3JkID0gJHdvcmQgLiAnICcgLiAkc3BlbGxpbmdbJHNlY29uZERpZ2l0XTsKICAgICAgICB9ICAgICAgIAogICAgICAgICR0aGlyZERpZ2l0ID0gJG51bWJlciAlIDEwOwogICAgICAgIGlmICgkdGhpcmREaWdpdCAhPSAwKSB7CiAgICAgICAgICAgICR3b3JkID0gJHdvcmQgLiAnICcgLiAkc3BlbGxpbmdbJHRoaXJkRGlnaXRdOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAkd29yZDsgICAKICAgIH0KICAgIAogICAgZnVuY3Rpb24gbnVtYmVyVG9UZXh0KCRudW1iZXIpIHsKICAgICAgICAkbnVtYmVyID0gc3BsaXROdW1iZXJUb1RleHQoJG51bWJlcikgLiAnICcgLiAnKCcgLiAkbnVtYmVyIC4gJyknIC4gaW5jbGluZVdvcmQoJG51bWJlcik7CiAgICAgICAgcmV0dXJuICRudW1iZXI7CiAgICB9CiAgICAKICAgICRhbW91bnQxID0gbXRfcmFuZCgxLDk5OTk5OTk5KTsKICAgICR0ZXh0MSA9IG51bWJlclRvVGV4dCgkYW1vdW50MSk7CiAgICBlY2hvICLQndCwINCy0LDRiNC10Lwg0YHRh9C10YLRg3skdGV4dDF9XG4iOwogICAgIAogICAgJGFtb3VudDIgPSBtdF9yYW5kKDEsOTk5OTk5OTkpOwogICAgJHRleHQyID0gbnVtYmVyVG9UZXh0KCRhbW91bnQyKTsKICAgIGVjaG8gItCd0LAg0LLQsNGI0LXQvCDRgdGH0LXRgtGDeyR0ZXh0Mn1cbiI7CiAgICAKICAgICRhbW91bnQzID0gbXRfcmFuZCgxLDk5OTk5OTk5KTsKICAgICR0ZXh0MyA9IG51bWJlclRvVGV4dCgkYW1vdW50Myk7CiAgICBlY2hvICLQndCwINCy0LDRiNC10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