<?php
// Staring straight up into the sky ... oh my my
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord( $number , $word1 , $word2 , $word5 ) {
$word = "" ;
if ( floor ( ( $number % 100 ) / 10 ) == 1 ) { $word = $word5 ;
} else {
switch ( $number % 10 ) {
case 1 :
$word = $word1 ;
break ;
case 2 :
case 3 :
case 4 :
$word = $word2 ;
break ;
default :
$word = $word5 ;
break ;
}
}
return $word ;
/* DIY */
}
/*
Преобразует числа от 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 => 'девятнадцать'
) ;
1 => 'одна' , 2 => 'две'
) ;
$result = "" ;
$num = floor ( $number / 100 ) ;
if ( $num != 0 ) {
$result .= $spelling [ $num * 100 ] . " " ;
}
$num = $number % 100 ;
if ( floor ( $num / 10 ) == 1 ) { $result .= $spelling [ $num ] . " " ;
}
else {
if ( $dec != 0 ) {
$result .= $spelling [ $dec * 10 ] . " " ;
}
$units = $num % 10 ;
if ( $units != 0 ) {
if ( $isFemale && ( $units === 1 || $units === 2 ) ) {
$result .= $femaleSpelling [ $units ] . " " ;
} else {
$result .= $spelling [ $units ] . " " ;
}
} else if ( $result === "" ) {
$result .= $spelling [ $units ] ;
}
}
return $result ;
/* DIY */
}
function numberToText( $number ) {
$result = "" ;
$num = floor ( $number / 1000 ) ;
while ( $num != 0 ) {
if ( floor ( $num / 1000 ) != 0 ) { $result .= smallNumberToText
( floor ( $num / 1000 ) , false ) . inclineWord
( floor ( $num / 1000 ) , "миллион " , "миллиона " , "миллионов " ) ; $num %= 1000 ;
} else {
$result .= smallNumberToText( $num , true ) . inclineWord( $num , "тысяча " , "тысячи " , "тысяч " ) ;
$num = floor ( $num / 1000 ) ; }
}
$result .= smallNumberToText( $number % 1000 , false ) . inclineWord( $number , "рубль" , "рубля" , "рублей" ) ;
return $result ;
/* DIY */
}
/* Вызовем функцию несколько раз */
$text1 = numberToText( $amount1 ) ;
echo "На вашем счету {$text1} \n " ;
$text2 = numberToText( $amount2 ) ;
echo "На вашем счету {$text2} \n " ;
$text3 = numberToText( $amount3 ) ;
echo "На вашем счету {$text3} \n " ;
$text4 = numberToText( $amount4 ) ;
echo "На вашем счету {$text4} \n " ;
PD9waHAKCi8vIFN0YXJpbmcgc3RyYWlnaHQgdXAgaW50byB0aGUgc2t5IC4uLiBvaCBteSBteQplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCgovKiDQktC+0LfQstGA0LDRidCw0LXRgiDRgdC+0L7RgtCy0LXRgtGB0YLQstGD0Y7RidGD0Y4g0YfQuNGB0LvRgyDRhNC+0YDQvNGDINGB0LvQvtCy0LA6IDEg0YDRg9Cx0LvRjCwgMiDRgNGD0LHQu9GPLCA1INGA0YPQsdC70LXQuSAqLwpmdW5jdGlvbiBpbmNsaW5lV29yZCgkbnVtYmVyLCAkd29yZDEsICR3b3JkMiwgJHdvcmQ1KSB7Cgkkd29yZCA9ICIiOwoJCglpZiAoZmxvb3IoKCR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YHQtdC80YzRgdC+0YInLAogICAgICAgIDggICA9PiAgJ9Cy0L7RgdC10LzRjCcsICAgICAgIDE4ICA9PiAgJ9Cy0L7RgdC10LzQvdCw0LTRhtCw0YLRjCcsICAgICA5MCAgPT4gICfQtNC10LLRj9C90L7RgdGC0L4nLCAgICAgOTAwID0+ICAn0LTQtdCy0Y/RgtGM0YHQvtGCJywKICAgICAgICA5ICAgPT4gICfQtNC10LLRj9GC0YwnLCAgICAgICAxOSAgPT4gICfQtNC10LLRj9GC0L3QsNC00YbQsNGC0YwnICAgIAogICAgKTsKICAgIAogICAgJGZlbWFsZVNwZWxsaW5nID0gYXJyYXkoCiAgICAgICAgMSAgID0+ICAn0L7QtNC90LAnLCAgICAgICAgMiAgID0+ICAn0LTQstC1JwogICAgKTsKICAgIAogICAgJHJlc3VsdCA9ICIiOwogICAgJG51bSA9IGZsb29yKCRudW1iZXIgLyAxMDApOwogICAgCiAgICBpZiAoJG51bSAhPSAwKSB7CiAgICAJJHJlc3VsdCAuPSAkc3BlbGxpbmdbJG51bSAqIDEwMF0gLiAiICI7CiAgICB9CiAgICAkbnVtID0gJG51bWJlciAlIDEwMDsKICAgIGlmIChmbG9vcigkbnVtIC8gMTApID09IDEpIHsKICAgIAkkcmVzdWx0IC49ICRzcGVsbGluZ1skbnVtXSAuICIgIjsKICAgIH0KICAgIGVsc2UgewogICAgCSRkZWMgPSBmbG9vcigkbnVtIC8gMTApOwogICAgCWlmICgkZGVjICE9IDApIHsKICAgIAkJJHJlc3VsdCAuPSAkc3BlbGxpbmdbJGRlYyAqIDEwXSAuICIgIjsKICAgIAl9CiAgICAJJHVuaXRzID0gJG51bSAlIDEwOwogICAgCWlmICgkdW5pdHMgIT0gMCkgewogICAgCQlpZiAoJGlzRmVtYWxlICYmICgkdW5pdHMgPT09IDEgfHwgJHVuaXRzID09PSAyKSkgewogICAgCQkJJHJlc3VsdCAuPSAkZmVtYWxlU3BlbGxpbmdbJHVuaXRzXSAuICIgIjsKICAgIAk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