<?php
function spellSmallNumber( $number , $female = null ) {
$last2Digits = $number % 100 ;
$lastDigit = $number % 10 ;
$hundreds = $number - $last2Digits ;
$decades = $last2Digits - ( $number % 10 ) ;
$words = [ ] ;
1 => 'одна' , 2 => 'две'
) ;
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 ( $number == 0 ) {
return $numbertoWords [ $number ] ;
} else {
if ( $hundreds != 0 ) { //Сотни
$words [ ] = $numbertoWords [ $hundreds ] ;
}
if ( $last2Digits >= 10 && $last2Digits <= 19 ) { // 10-19
$words [ ] = $numbertoWords [ $last2Digits ] ;
} else {
if ( $decades != 0 ) { //Десятки
$words [ ] = $numbertoWords [ $decades ] ;
}
if ( $female == 1 && ( $lastDigit == 1 || $lastDigit == 2 ) ) {
$words [ ] = $femaleSpelling [ $lastDigit ] ; //Единицы
} else {
if ( $lastDigit != 0 ) {
$words [ ] = $numbertoWords [ $lastDigit ] ;
}
}
}
}
return $result ;
}
function inclineWord ( $number , $word1 , $word2 , $word5 ) {
$last2Digits = $number % 100 ;
$lastDigit = $number % 10 ;
if ( $last2Digits >= 11 && $last2Digits <= 14 ) {
return $word5 ;
} elseif ( $lastDigit == 1 ) {
return $word1 ;
} elseif ( $lastDigit >= 2 && $lastDigit <= 4 ) {
return $word2 ;
} else {
return $word5 ;
}
}
function spellNumber( $number ) {
$words = [ ] ;
$millions = floor ( $number / 1000000 ) ; $thousands = floor ( $number / 1000 % 1000 ) ; $units = $number % 1000 ;
$millionstoWords = spellSmallNumber( $millions ) . " " . inclineWord( $millions , "миллион " , "миллиона " , "миллионов " ) ;
$thousandstoWords = spellSmallNumber( $thousands , 1 ) . " " . inclineWord( $thousands , "тысяча " , "тысячи " , "тысяч " ) ;
$unitstoWords = spellSmallNumber( $units ) . " " . inclineWord( $units , "рубль " , "рубля " , "рублей " ) ;
if ( $millions == 0 ) {
} else {
$words [ ] = $millionstoWords ;
}
if ( $thousands == 0 ) {
} else {
$words [ ] = $thousandstoWords ;
}
if ( $units == 0 && $number != 0 ) {
$words [ ] = inclineWord( $units , "рубль " , "рубля " , "рублей " ) ;
} else {
$words [ ] = $unitstoWords ;
}
return $result ;
}
$text1 = spellNumber( $amount1 ) ;
echo "На вашем счету {$text1} \n " ;
$text2 = spellNumber( $amount2 ) ;
echo "На вашем счету {$text2} \n " ;
$text3 = spellNumber( $amount3 ) ;
echo "На вашем счету {$text3} \n " ;
$text4 = spellNumber( $amount4 ) ;
echo "На вашем счету {$text4} \n " ;
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKZnVuY3Rpb24gc3BlbGxTbWFsbE51bWJlcigkbnVtYmVyLCAkZmVtYWxlID0gbnVsbCl7CiAgICAkbGFzdDJEaWdpdHMgPSAkbnVtYmVyICUgMTAwOwogICAgJGxhc3REaWdpdCA9ICRudW1iZXIgJSAxMDsKICAgICRodW5kcmVkcyA9ICRudW1iZXIgLSAkbGFzdDJEaWdpdHM7CiAgICAkZGVjYWRlcyA9ICRsYXN0MkRpZ2l0cyAtICgkbnVtYmVyICUgMTApOwogICAgJHdvcmRzID0gW107CiAgICAkZmVtYWxlU3BlbGxpbmcgPSBhcnJheSgKICAgICAgICAxICAgPT4gICfQvtC00L3QsCcsICAgICAgICAyICAgPT4gICfQtNCy0LUnCiAgICApOwogICAgJG51bWJlcnRvV29yZHMgPSBhcnJheSgKICAgICAgICAwICAgPT4gICfQvdC+0LvRjCcsICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMCAgPT4gICfQtNC10YHRj9GC0YwnLCAgICAgICAxMDAgPT4gICfRgdGC0L4nLAogICAgICAgIDEgICA9PiAgJ9C+0LTQuNC9JywgICAgICAgICAxMSAgPT4gICfQvtC00LjQvdC90LDQtNGG0LDRgtGMJywgICAgICAyMCAgPT4gICfQtNCy0LDQtNGG0LDRgtGMJywgICAgIDIwMCA9PiAgJ9C00LLQtdGB0YLQuCcsCiAgICAgICAgMiAgID0+ICAn0LTQstCwJywgICAgICAgICAgMTIgID0+ICAn0LTQstC10L3QsNC00YbQsNGC0YwnLCAgICAgICAzMCAgPT4gICfRgtGA0LjQtNGG0LDRgtGMJywgICAgIDMwMCA9PiAgJ9GC0YDQuNGB0YLQsCcsCiAgICAgICAgMyAgID0+ICAn0YLRgNC4JywgICAgICAgICAgMTMgID0+ICAn0YLRgNC40L3QsNC00YbQsNGC0YwnLCAgICAgICA0MCAgPT4gICfRgdC+0YDQvtC6JywgICAgICAgIDQwMCA9PiAgJ9GH0LXRgtGL0YDQtdGB0YLQsCcsCiAgICAgICAgNCAgID0+ICAn0YfQtdGC0YvRgNC1JywgICAgICAgMTQgID0+ICAn0YfQtdGC0YvRgNC90LDQtNGG0LDRgtGMJywgICAgIDUwICA9PiAgJ9C/0Y/RgtGM0LTQtdGB0Y/RgicsICAgIDUwMCA9PiAgJ9C/0Y/RgtGM0YHQvtGCJywKICAgICAgICA1ICAgPT4gICfQv9GP0YLRjCcsICAgICAgICAgMTUgID0+ICAn0L/Rj9GC0L3QsNC00YbQsNGC0YwnLCAgICAgICA2MCAgPT4gICfRiNC10YHRgtGM0LTQtdGB0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