<?php
function inclineWord( $number , $word1 , $word2 , $word5 ) {
if ( $number % 10 == 0 ) {
return $word5 ;
}
elseif ( ( $number % 100 >= 11 ) && ( $number % 100 <= 14 ) ) {
return $word5 ;
}
elseif ( $number % 10 == 1 ) {
return $word1 ;
}
elseif ( $number % 10 < 5 ) {
return $word2 ;
}
else { return $word5 ; }
}
function checkFemale( $number ) {
if ( $number < 10000 ) {
$number = floor ( $number / 1000 ) ; if ( $number == 1 || $number == 2 ) { return 1 ; }
else { return 0 ; }
}
else {
$number = floor ( $number / 1000 % 100 ) ; if ( $number == 11 || $number == 12 ) { return 0 ; }
elseif ( $number % 10 == 1 || $number % 10 == 2 ) { return 1 ; }
else { return 0 ; }
}
}
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 => 'девятнадцать'
) ;
1 => 'одна' , 2 => 'две'
) ;
if ( $isFemale == 1 ) {
return preg_replace ( '/ноль/' , '' , $spelling [ floor ( $number / 100 ) * 100 ] . " " . $spelling [ floor ( $number % 100 / 10 ) * 10 ] . " " . $femaleSpelling [ $number % 10 ] ) ; }
if ( $number == 0 ) {
return $spelling [ $number ] ;
}
elseif ( ( $number % 100 ) == 0 ) {
return $spelling [ floor ( $number / 100 ) * 100 ] ; //900 }
elseif ( $number % 100 < 20 ) {
return preg_replace ( '/^ноль/' , '' , $spelling [ floor ( $number / 100 ) * 100 ] . " " . $spelling [ $number % 100 ] . " " ) ; //913 }
elseif ( $number % 100 > 19 && $number % 10 == 0 ) {
return preg_replace ( '/^ноль/' , '' , $spelling [ floor ( $number / 100 ) * 100 ] . " " . $spelling [ $number / 10 % 10 * 10 ] . " " ) ; //990 }
else {
return preg_replace ( '/^ноль/' , '' , $spelling [ floor ( $number / 100 ) * 100 ] . " " . $spelling [ floor ( ( $number % 100 ) / 10 ) * 10 ] . " " . $spelling [ $number % 10 ] ) ; //999 }
}
function numberToText( $number ) {
if ( $number < 1000 ) {
return smallNumberToText( $number , 0 ) . " " . inclineWord( $number , "рубль" , "рубля" , "рублей" ) ;
}
elseif ( $number == 1000 ) {
return "одня тысяча рублей" ;
}
elseif ( $number < 1000000 ) {
$female = checkFemale( $number ) ;
$impNumber = [ 0 , 1 ] ;
$impNumber [ 0 ] = smallNumberToText
( floor ( $number / 1000 ) , $female ) . " " . inclineWord
( floor ( $number / 1000 ) , "тысяча" , "тысячи" , "тысяч" ) ; $impNumber [ 1 ] = smallNumberToText( $number % 1000 , 0 ) . " " . inclineWord( $number , "рубль" , "рубля" , "рублей" ) ;
}
elseif ( $number == 1000000 ) {
return "один миллион рублей" ;
}
elseif ( $number < 100000000 ) {
$female = checkFemale( $number ) ;
$impNumber = [ 0 , 1 , 2 ] ; //222
$impNumber [ 0 ] = smallNumberToText
( floor ( $number / 1000000 ) , 0 ) . " " . inclineWord
( floor ( $number / 1000000 ) , "миллион" , "миллиона" , "миллионов" ) ; $impNumber [ 1 ] = smallNumberToText
( floor ( $number % 1000000 / 1000 ) , $female ) . " " . inclineWord
( floor ( $number % 1000000 / 1000 ) , "тысяча" , "тысячи" , "тысяч" ) ; $impNumber [ 2 ] = smallNumberToText( $number % 1000 , 0 ) . " " . inclineWord( $number , "рубль" , "рубля" , "рублей" ) ;
}
}
$text1 = numberToText( $amount1 ) ;
echo "На вашем счету {$text1} <br>" ;
$text2 = numberToText( $amount2 ) ;
echo "На вашем счету {$text2} <br>" ;
$text3 = numberToText( $amount3 ) ;
echo "На вашем счету {$text3} <br>" ;
$text4 = numberToText( $amount4 ) ;
echo "На вашем счету {$text4} <br>" ;
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Cm1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwoKZnVuY3Rpb24gaW5jbGluZVdvcmQoJG51bWJlciwgJHdvcmQxLCAkd29yZDIsICR3b3JkNSkgewogICAgaWYoJG51bWJlciUxMCA9PSAwKSB7CiAgICAgICAgcmV0dXJuICR3b3JkNTsKICAgIH0KICAgIGVsc2VpZigoJG51bWJlciUxMDAgPj0gMTEpICYmICgkbnVtYmVyJTEwMCA8PSAxNCkpIHsKICAgICAgICByZXR1cm4gJHdvcmQ1OwogICAgfQogICAgZWxzZWlmKCRudW1iZXIlMTAgPT0gMSkgewogICAgICAgIHJldHVybiAkd29yZDE7CiAgICB9CiAgICBlbHNlaWYoJG51bWJlciUxMCA8IDUpIHsKICAgICAgICByZXR1cm4gJHdvcmQyOwogICAgfQogICAgZWxzZSB7IHJldHVybiAkd29yZDU7IH0KfQoKZnVuY3Rpb24gY2hlY2tGZW1hbGUoJG51bWJlcikgewogICAgaWYoJG51bWJlciA8IDEwMDAwKSB7CiAgICAgICAgJG51bWJlciA9IGZsb29yKCRudW1iZXIvMTAwMCk7CiAgICAgICAgaWYoJG51bWJlciA9PSAxIHx8ICRudW1iZXIgPT0yKSB7IHJldHVybiAxOyB9CiAgICAgICAgZWxzZSB7IHJldHVybiAwOyB9CiAgICB9CiAgICBlbHNlIHsKICAgICAgICAkbnVtYmVyID0gZmxvb3IoJG51bWJlci8xMDAwJTEwMCk7CiAgICAgICAgaWYoJG51bWJlciA9PSAxMSB8fCAkbnVtYmVyID09IDEyKSB7IHJldHVybiAwOyB9CiAgICAgICAgZWxzZWlmICgkbnVtYmVyJTEwID09IDEgfHwgJG51bWJlciUxMCA9PSAyKSB7IHJldHVybiAxOyB9CiAgICAgICAgZWxzZSB7IHJldHVybiAwOyB9CiAgICB9Cn0KCmZ1bmN0aW9uIHNtYWxsTnVtYmVyVG9UZXh0KCRudW1iZXIsICRpc0ZlbWFsZSkgewogICAgCiAgICAkc3BlbGxpbmcgPSBhcnJheSgKICAgICAgICAwICAgPT4gICfQvdC+0LvRjCcsICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEwICA9PiAgJ9C00LXRgdGP0YLRjCcsICAgICAgIDEwMCA9PiAgJ9GB0YLQvicsCiAgICAgICAgMSAgID0+ICAn0L7QtNC40L0nLCAgICAgICAgIDExICA9PiAgJ9C+0LTQuNC90L3QsNC00YbQsNGC0YwnLCAgICAgIDIwICA9PiAgJ9C00LLQsNC00YbQsNGC0YwnLCAgICAgMjAwID0+ICAn0LTQstC10YHRgtC4JywKICAgICAgICAyICAgPT4gICfQtNCy0LAnLCAgICAgICAgICAxMiAgPT4gICfQtNCy0LXQvdCw0LTRhtCw0YLRjCcsICAgICAgIDMwICA9PiAgJ9GC0YDQuNC00YbQsNGC0YwnLCAgICAgMzAwID0+ICAn0YLRgNC40YHRgtCwJywKICAgICAgICAzICAgPT4gICfRgtGA0LgnLCAgICAgICAgICAxMyAgPT4gICfRgtGA0LjQvdCw0LTRhtCw0YLRjCcsICAgICAgIDQwICA9PiAgJ9GB0L7RgNC+0LonLCAgICAgICAgNDAwID0+ICAn0YfQtdGC0YvRgNC10YHRgtCwJywKICAgICAgICA0ICAgPT4gICfRh9C10YLRi9GA0LUnLCAgICAgICAxNCAgPT4gICfRh9C10YLRi9GA0L3QsNC00YbQsNGC0YwnLCAgICAgNTAgID0+ICAn0L/Rj9GC0YzQtNC10YHRj9GCJywgICAgNTAwID0+ICAn0L/Rj9GC0YzRgdC+0YInLAogICAgICAgIDUgICA9PiAgJ9C/0Y/RgtGMJywgICAgIC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