<?php
$isFemale = 0 ;
function smallNumberToText( $number , $isFem ) {
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 == 1 ) || ( $number ) == 2 ) && ( $isFem == 1 ) )
echo $femaleSpelling [ $number ] . " " ;
else
echo $spelling [ $number ] . " " ;
}
function numberToText( $number ) { //разбивает число на сотни/тысячи/миллионы и передает в функцию отсылающую значение в smallNumberToText
if ( $len <= 3 )
{ $GLOBALS [ 'isFemale' ] = 0 ;
nameIt( $number ) ; }
elseif ( $len > 3 && $len <= 6 )
{
settype ( $number , "string" ) ; //этот пиздец if ( $number [ strlen ( $number ) - 4 ] == 1 ) //проверяет последние цифры $GLOBALS [ 'isFemale' ] = 1 ; //тысяч
elseif ( $number [ strlen ( $number ) - 4 ] == 2 ) //и меняет $GLOBALS [ 'isFemale' ] = 1 ; //род
else // на женский
$GLOBALS [ 'isFemale' ] = 0 ;
nameIt
( floor ( $number / 1000 ) ) ;
settype ( $number , "string" ) ; //этот пиздец if ( $number [ strlen ( $number ) - 4 ] == 1 ) //проверяет последние цифры echo "тысяча " ; //тысяч
elseif ( $number [ strlen ( $number ) - 4 ] == 2 ) //и меняет echo "тысячи " ; //"тысяч" на "тысячи"
else //в зависимости от рода
{ echo " тысяч " ;
$GLOBALS [ 'isFemale' ] = 0 ; }
numberToText
( $number - ( floor ( $number / 1000 ) ) * 1000 ) ; }
elseif ( $len > 6 && $len <= 9 )
{
nameIt
( floor ( $number / 1000000 ) ) ; settype ( $number , "string" ) ; //этот пиздец if ( $number [ strlen ( $number ) - 7 ] == 1 ) //проверяет последние цифры echo " миллион " ; //миллионов
elseif ( $number [ strlen ( $number ) - 7 ] >= 2 && $number [ strlen ( $number ) - 7 ] <= 4 ) //и выбирает echo " миллиона " ; //нужную форму
else
echo " миллионов " ;
numberToText
( $number - ( floor ( $number / 1000000 ) ) * 1000000 ) ; $GLOBALS [ 'isFemale' ] = 0 ;
}
else die ( "ERROR! length=$len " ) ;
}
function nameIt( $value ) //передает значения в smallNumberToText с учетом исключений
{
$A = ( string) $value ;
switch ( $len )
{
case "3" :
smallNumberToText( $A [ 0 ] * 100 , $GLOBALS [ 'isFemale' ] ) ;
if ( ( $A [ 1 ] . $A [ 2 ] ) == "00" ) break ; //100,200..900
if ( ( $A [ 1 ] . $A [ 2 ] ) >= "10" && ( $A [ 1 ] . $A [ 2 ] ) <= "19" ) { smallNumberToText( $A [ 1 ] . $A [ 2 ] , $GLOBALS [ 'isFemale' ] ) ; break ; } //11,12..19
smallNumberToText( $A [ 1 ] * 10 , $GLOBALS [ 'isFemale' ] ) ;
smallNumberToText( $A [ 2 ] , $GLOBALS [ 'isFemale' ] ) ; break ;
case "2" :
if ( ( $A [ 0 ] . $A [ 1 ] ) >= "10" && ( $A [ 0 ] . $A [ 1 ] ) <= "19" ) { smallNumberToText( $A [ 0 ] . $A [ 1 ] , $GLOBALS [ 'isFemale' ] ) ; break ; } //11,12..19
smallNumberToText( $A [ 0 ] * 10 , $GLOBALS [ 'isFemale' ] ) ;
smallNumberToText( $A [ 1 ] , $GLOBALS [ 'isFemale' ] ) ; break ;
case "1" :
smallNumberToText( $A [ 0 ] , $GLOBALS [ 'isFemale' ] ) ; break ;
}
}
function addRubles( $value )
{
$lastNumber = $value [ $length - 2 ] . $value [ $length - 1 ] ;
if ( $lastNumber >= "02" && $lastNumber <= "04" )
echo " рубля." ;
elseif ( $lastNumber == "01" )
echo " рубль." ;
elseif ( ( $lastNumber >= "05" && $lastNumber <= "09" ) )
echo " рублей." ;
elseif ( $lastNumber >= "10" && $lastNumber <= "20" )
echo " рублей." ;
elseif ( $value [ $length - 1 ] == "1" && $value [ $length - 2 ] != "1" )
echo " рубль." ;
elseif ( ( $value [ $length - 1 ] >= "2" && $value [ $length - 1 ] <= "4" ) && ( $value [ $length - 2 ] != "2" || $value [ $length - 2 ] != "0" ) )
echo " рубля." ;
else
echo " рублей." ;
}
echo "На вашем счету ($amount1 ) " , numberToText( $amount1 ) , addRubles( $amount1 ) , "\n " ;
echo "На вашем счету ($amount2 ) " , numberToText( $amount2 ) , addRubles( $amount2 ) , "\n " ;
echo "На вашем счету ($amount3 ) " , numberToText( $amount3 ) , addRubles( $amount3 ) , "\n " ;
echo "На вашем счету ($amount4 ) " , numberToText( $amount4 ) , addRubles( $amount4 ) , "\n " ;
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CgokaXNGZW1hbGU9MDsKIApmdW5jdGlvbiBzbWFsbE51bWJlclRvVGV4dCgkbnVtYmVyLCAkaXNGZW0pIHsKCiAgICAkc3BlbGxpbmcgPSBhcnJheSgKCiAgICAgICAgMCAgID0+ICAnJywgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTAgID0+ICAn0LTQtdGB0Y/RgtGMJywgICAgICAgMTAwID0+ICAn0YHRgtC+JywKCiAgICAgICAgMSAgID0+ICAn0L7QtNC40L0nLCAgICAgICAgIDExICA9PiAgJ9C+0LTQuNC90L3QsNC00YbQsNGC0YwnLCAgICAgIDIwICA9PiAgJ9C00LLQsNC00YbQsNG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