<?php
function inclineWord( $number , $words ) {
if ( ( ( $number % 10 ) == 1 ) && ( ( $number % 100 ) != 11 ) ) {
$type = 0 ;
} elseif ( ( ( $number % 10 ) > 1 ) && ( ( $number % 10 ) < 5 ) && ( ( ( $number % 100 ) < 12 ) || ( ( $number % 100 ) > 14 ) ) ) {
$type = 1 ;
} else {
$type = 2 ;
}
return $words [ $type ] ;
}
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 ( $number > 0 ) {
foreach ( $spelling as $delimeter => $string ) {
if ( ( $delimeter > 0 ) && ( ( $number / $delimeter ) >= 1 ) ) {
$remain = ( $number % $delimeter ) ;
$return [ ] = $string ;
if ( $remain > 20 ) {
$return [ ] = smallNumberToText( $remain , $isFemale ) ;
} elseif ( $remain > 0 ) {
if ( ( $isFemale == 1 ) && isset ( $femaleSpelling [ $remain ] ) ) {
$return [ ] = $femaleSpelling [ $remain ] ;
} else {
$return [ ] = $spelling [ $remain ] ;
}
}
break ;
}
}
} else {
$return [ ] = $spelling [ 0 ] ;
}
}
function numberToText( $number ) {
$rubles = array ( 'рубль' , 'рубля' , 'рублей' ) ;
1000 => array ( 'тысяча' , 'тысячи' , 'тысяч' ) , 1000000 => array ( 'миллион' , 'миллиона' , 'миллионов' ) , 1000000000 => array ( 'миллиард' , 'миллиарда' , 'миллиардов' ) ) ;
$initNumber = $number ;
if ( $number > 999 ) {
foreach ( $bigNumbers as $delimeter => $string ) {
$isFemale = 0 ; // по умолчанию мужской род, т.к. женский только для тысяч
if ( ( $count = $number / $delimeter ) >= 1 ) {
$remain = ( $number % $delimeter ) ;
if ( $delimeter == 1000 ) { $isFemale = 1 ; }
$return [ ] = smallNumberToText
( floor ( $count ) , $isFemale ) . " " . inclineWord
( floor ( $count ) , $string ) ;
$number = $remain ;
}
}
}
$stringNumber = smallNumberToText( $number , 0 ) ;
return implode ( " " , $return ) . " $stringNumber ($initNumber ) " . inclineWord
( $initNumber , $rubles ) ;
} else {
return "$stringNumber ($initNumber ) " . inclineWord( $initNumber , $rubles ) ;
}
}
/* Вызовем функцию несколько раз */
$amount1 = mt_rand ( 999999999 , 99999999999 ) ; $text1 = numberToText( $amount1 ) ;
echo "На вашем счету {$text1} \n " ;
$text2 = numberToText( $amount2 ) ;
echo "На вашем счету {$text2} \n " ;
$text3 = numberToText( $amount3 ) ;
echo "На вашем счету {$text3} \n " ;
$amount4 = 1000001 ;
$text4 = numberToText( $amount4 ) ;
echo "На вашем счету {$text4} \n " ;
$amount5 = 550 ;
$text5 = numberToText( $amount5 ) ;
echo "На вашем счету {$text5} \n " ;
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CgpmdW5jdGlvbiBpbmNsaW5lV29yZCgkbnVtYmVyLCAkd29yZHMpIHsKICAgIAogICAgaWYgKCgoJG51bWJlciAlIDEwKSA9PSAxKSAmJiAoKCRudW1iZXIgJSAxMDApICE9IDExKSkgewogICAgICAgIAogICAgICAgICR0eXBlID0gMDsKICAgICAgICAKICAgIH0gZWxzZWlmICgoKCRudW1iZXIgJSAxMCkgPiAxKSAmJiAoKCRudW1iZXIgJSAxMCkgPCA1KSAmJiAoKCgkbnVtYmVyICUgMTAwKSA8IDEyKSB8fCAoKCRudW1iZXIgJSAxMDApID4gMTQpKSkgewogICAgICAgIAogICAgICAgICR0eXBlID0gMTsKICAgICAgICAKICAgIH0gZWxzZSB7CiAgICAgICAgCiAgICAgICAgJHR5cGUgPSAyOwogICAgICAgIAogICAgfQoKICAgIHJldHVybiAkd29yZHNbJHR5cGVdOwogICAgCn0KCmZ1bmN0aW9uIHNtYWxsTnVtYmVyVG9UZXh0KCRudW1iZXIsICRpc0ZlbWFsZSkgewogICAgCiAgICAkc3BlbGxpbmcgPSBhcnJheSgKICAgICAgICAwICAgPT4gICfQvdC+0LvRjCcsICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEwICA9PiAgJ9C00LXRgdGP0YLRjCcsICAgICAgIDEwMCA9PiAgJ9GB0YLQvicsCiAgICAgICAgMSAgID0+ICAn0L7QtNC40L0nLCAgICAgICAgIDExICA9PiAgJ9C+0LTQuNC90L3QsNC00YbQsNGC0YwnLCAgICAgIDIwICA9PiAgJ9C00LLQsNC00YbQsNGC0YwnLCAgICAgMjAwID0+ICAn0LTQstC10YHRgtC4JywKICAgICAgICAyICAgPT4gICfQtNCy0LAnLCAgICAgICAgICAxMiAgPT4gICfQtNCy0LXQvdCw0LTRhtCw0YLRjCcsICAgICAgIDMwICA9PiAgJ9GC0YDQuNC00YbQsNGC0YwnLCAgICAgMzAwID0+ICAn0YLRgNC40YHRgtCwJywKICAgICAgICAzICAgPT4gICfRgtGA0LgnLCAgICAgICAgICAxMyAgPT4gICfRgtGA0LjQvdCw0LTRhtCw0YLRjCcsICAgICAgIDQwICA9PiAgJ9GB0L7RgNC+0LonLCAgICAgICAgNDAwID0+ICAn0YfQtdGC0YvRgNC10YHRgtCwJywKICAgICAgICA0ICAgPT4gICfRh9C10YLRi9GA0LUnLCAgICAgICAxNCAgPT4gIC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AgIAogICAgKTsKICAgIAogICAga3Jzb3J0KCRzcGVsbGluZyk7CiAgICAKICAgIGlmICgkbnVtYmVyID4gMCkgewogIAogICAgICAgIGZvcmVhY2ggKCRzcGVsbGluZyBhcyAkZGVsaW1ldGVyID0+ICRzdHJpbmcpIHsKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmICgoJGRlbGltZXRlciA+IDAgKSAmJiAoKCRudW1iZXIgLyAkZGVsaW1ldGVyKSA+PSAxKSkgewogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAkcmVtYWluID0gKCRudW1iZXIgJSAkZGVsaW1ldGVyKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgJHJldHVybltdID0gJHN0cmluZzsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaWYgKCRyZW1haW4gPiAyMCkgewogICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICRyZXR1cm5bXSA9IHNtYWxsTnVtYmVyVG9UZXh0KCRyZW1haW4sICRpc0ZlbWFsZSk7CiAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICB9IGVsc2VpZiAoJHJlbWFpbiA+IDApIHsKICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICBpZiAoKCRpc0ZlbWFsZSA9PSAxKSAmJiBpc3NldCgkZmVtYWxlU3BlbGxpbmdbJHJlbWFpbl0pKSB7CgogICAgICAgICAgICAgICAgICAgICAgICAkcmV0dXJuW10gPSAkZmVtYWxlU3BlbGxpbmdbJHJlbWFpbl07CiAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAkcmV0dXJuW10gPSAkc3BlbGxpbmdbJHJlbWFpbl07CiAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgCiAgICB9IGVsc2UgewogICAgICAgIAogICAgICAgICRyZXR1cm5bXSA9ICRzcGVsbGluZ1swXTsKICAgICAgICAKICAgIH0KICAgIAogICAgcmV0dXJuIGltcGxvZGUoIiAiLCRyZXR1cm4pOwogICAgCn0KCgpmdW5jdGlvbiBudW1iZXJUb1RleHQoJG51bWJlcikgewogICAgCiAgICAkcnVibGVzID0gYXJyYXkoJ9GA0YPQsdC70YwnLCfRgNGD0LHQu9GPJywn0YDRg9Cx0LvQtdC5Jyk7CiAgICAKICAgICRiaWdOdW1iZXJzID0gYXJyYXkoCiAgICAgICAgMTAwMCAgICAgICAgPT4gYXJyYXkgKCfRgtGL0YHRj9GH0LAnLCAn0YLRi9GB0Y/Rh9C4JywgJ9GC0YvRgdGP0YcnKSwKICAgICAgICAxMDAwMDAwICAgICA9PiBhcnJheSAoJ9C80LjQu9C70LjQvtC9JywgJ9C80LjQu9C70LjQvtC90LAnLCAn0LzQuNC70LvQuNC+0L3QvtCyJyksCiAgICAgICAgMTAwMDAwMDAwMCAgPT4gYXJyYXkgKCfQvNC40LvQu9C40LDRgNC0JywgJ9C80LjQu9C70LjQsNGA0LTQsCcsICfQvNC40LvQu9C40LDRgNC00L7QsicpCiAgICApOwogICAgCiAgICBrcnNvcnQoJGJpZ051bWJlcnMpOwogICAgCiAgICAkaW5pdE51bWJlciA9ICRudW1iZXI7CiAgICAKICAgIGlmICgkbnVtYmVyID4gOTk5KSB7CgogICAgICAgIGZvcmVhY2ggKCRiaWdOdW1iZXJzIGFzICRkZWxpbWV0ZXIgPT4gJHN0cmluZykgewoKICAgICAgICAgICAgJGlzRmVtYWxlID0gMDsgLy8g0L/QviDRg9C80L7Qu9GH0LDQvdC40Y4g0LzRg9C20YHQutC+0Lkg0YDQvtC0LCDRgi7Qui4g0LbQtdC90YHQutC40Lkg0YLQvtC70YzQutC+INC00LvRjyDRgtGL0YHRj9GHCgogICAgICAgICAgICBpZiAoKCRjb3VudCA9ICRudW1iZXIgLyAkZGVsaW1ldGVyKSA+PSAxKSB7CgogICAgICAgICAgICAgICAgJHJlbWFpbiA9ICgkbnVtYmVyICUgJGRlbGltZXRlcik7CgogICAgICAgICAgICAgICAgaWYgKCRkZWxpbWV0ZXIgPT0gMTAwMCkgeyAkaXNGZW1hbGUgPSAxOyB9CgogICAgICAgICAgICAgICAgJHJldHVybltdID0gc21hbGxOdW1iZXJUb1RleHQoZmxvb3IoJGNvdW50KSwgJGlzRmVtYWxlKSAuICIgIiAuIGluY2xpbmVXb3JkKGZsb29yKCRjb3VudCksJHN0cmluZyk7CgogICAgICAgICAgICAgICAgJG51bWJlciA9ICRyZW1haW47CgogICAgICAgICAgICB9CgogICAgICAgIH0KCiAgICB9CiAgICAKICAgICRzdHJpbmdOdW1iZXIgPSBzbWFsbE51bWJlclRvVGV4dCgkbnVtYmVyLCAwKTsKICAgIAogICAgCiAgICBpZiAoaXNzZXQoJHJldHVybikpIHsKICAgIAkKICAgICAgICByZXR1cm4gaW1wbG9kZSgiICIsICRyZXR1cm4pIC4gIiAkc3RyaW5nTnVtYmVyICgkaW5pdE51bWJlcikgIiAuIGluY2xpbmVXb3JkKCRpbml0TnVtYmVyLCAkcnVibGVzKTsKICAgICAgICAKICAgIH0gZWxzZSB7CiAgICAJCiAgICAgICAgcmV0dXJuICIkc3RyaW5nTnVtYmVyICgkaW5pdE51bWJlcikgIiAuIGluY2xpbmVXb3JkKCRpbml0TnVtYmVyLCAkcnVibGVzKTsKICAgICAgICAKICAgIH0KICAKfQoKLyog0JLRi9C30L7QstC10Lwg0YTRg9C90LrRhtC40Y4g0L3QtdGB0LrQvtC70YzQutC+INGA0LDQtyAqLwokYW1vdW50MSA9IG10X3JhbmQoOTk5OTk5OTk5LDk5OTk5OTk5OTk5K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