<?php
// Числа прописью
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord( $number , $word1 , $word2 , $word5 ) {
$word = "Енот наносит ответный удар" ; //правильная форма склонения
if ( 4 < $number % 100 && $number % 100 <= 19 ) {
$word = $word5 ;
} elseif ( $number % 10 == 1 ) {
$word = $word1 ;
} elseif ( $number % 10 >= 2 && $number % 10 <= 4 ) {
$word = $word2 ;
} elseif ( $number % 10 >= 5 || $number % 10 == 0 ) {
$word = $word5 ;
}
return $word ;
}
/*
Преобразует числа от 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 => 'две'
) ;
//числа прописью для каждого разряда
//числа прописью строкой
$text = '' ;
//если в числе есть сотни, добавляем слово для сотен
if ( $number >= 100 ) {
$numbers [ "0" ] = ( floor ( $number / 100 ) ) * 100 ; $numbers [ "0" ] = $spelling [ $numbers [ 0 ] ] ;
}
if ( 11 <= $number % 100 && $number % 100 <= 19 ) { //... слово для 11-19
$numbers [ "1" ] = $number % 100 ;
$numbers [ "1" ] = $spelling [ $numbers [ "1" ] ] ;
}
if ( 10 <= $number % 100 && $number % 100 <= 99 ) { //... слово десятков
$numbers [ "2" ] = floor ( ( $number % 100 ) / 10 ) * 10 ; $numbers [ "2" ] = $spelling [ $numbers [ "2" ] ] ;
}
if ( 1 <= $number % 10 && $number % 10 <= 9 ) { //... слово единиц
if ( ( $number % 10 == 1 || $number % 10 == 2 ) && $isFemale == 1 ) {
$numbers [ "3" ] = $number % 10 ;
$numbers [ "3" ] = $femaleSpelling [ $numbers [ "3" ] ] ;
} else {
$numbers [ "3" ] = $number % 10 ;
$numbers [ "3" ] = $spelling [ $numbers [ "3" ] ] ;
}
}
//склеиваем строку из слов
foreach ( $numbers as $key => $word ) {
$text .= $word . " " ;
if ( $key == 1 && $word != NULL ) {
break ;
}
}
return $text ;
}
function numberToText( $number ) {
$i = 0 ; //счетчик
$result = "" ; //число прописью одной строкой
$strs = array ( ) ; //разряды числа прописью $bit = 0 ; //текущий разряд - сотни, тыщи, миллионы
array ( "рубль" , "рубля" , "рублей" ) , array ( "тысяча" , "тысячи" , "тысяч" ) , array ( "миллион" , "миллиона" , "миллионов" ) ) ;
//продолжаем пока переименованнае число < исходного числа
while ( $i < $number ) {
//берем по очереди часть числа (3 цифры начиная справа)
// отправляем на переименовку и согласно разряду добавляем слово миллион, тысяч или рублей
$word = inclineWord( $pieceNumber , $words [ $bit ] [ 0 ] , $words [ $bit ] [ 1 ] , $words [ $bit ] [ 2 ] ) ;
if ( $bit == 1 ) {
$strs [ ] = smallNumberToText( $pieceNumber , 1 ) . $word ;
} else {
$strs [ ] = smallNumberToText( $pieceNumber , 0 ) . $word ;
}
//увеличиваем $i (счетчик)
$i += $pieceNumber * ( pow ( 1000 , $bit ) ) ;
//увеличиваем разряд
$bit ++;
}
//склеиваем результат в одну строку
foreach ( $strs as $str ) {
$result = $str . " " . $result ;
}
return $result ;
}
//Вызовем функцию несколько раз
$text1 = numberToText( $amount1 ) ;
echo "На вашем счету {$amount1} {$text1} \n " ;
$text2 = numberToText( $amount2 ) ;
echo "На вашем счету {$amount2} {$text2} \n " ;
$text3 = numberToText( $amount3 ) ;
echo "На вашем счету {$amount3} {$text3} \n " ;
$text4 = numberToText( $amount4 ) ;
echo "На вашем счету {$amount4} {$text4} \n " ;
?>
PD9waHAKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CgovLyDQp9C40YHQu9CwINC/0YDQvtC/0LjRgdGM0Y4KICAKLyog0JLQvtC30LLRgNCw0YnQsNC10YIg0YHQvtC+0YLQstC10YLRgdGC0LLRg9GO0YnRg9GOINGH0LjRgdC70YMg0YTQvtGA0LzRgyDRgdC70L7QstCwOiAxINGA0YPQsdC70YwsIDIg0YDRg9Cx0LvRjywgNSDRgNGD0LHQu9C10LkgKi8KZnVuY3Rpb24gaW5jbGluZVdvcmQoJG51bWJlciwgJHdvcmQxLCAkd29yZDIsICR3b3JkNSkgewogICAgCiAgICAkd29yZCA9ICLQldC90L7RgiDQvdCw0L3QvtGB0LjRgiDQvtGC0LLQtdGC0L3Ri9C5INGD0LTQsNGAIjsgLy/Qv9GA0LDQstC40LvRjNC90LDRjyDRhNC+0YDQvNCwINGB0LrQu9C+0L3QtdC90LjRjwogICAgCiAgICBpZiAoNCA8ICRudW1iZXIgJSAxMDAgJiYgJG51bWJlciAlIDEwMCA8PSAxOSkgewogICAgICAgICR3b3JkID0gJHdvcmQ1OwogICAgfSBlbHNlaWYgKCRudW1iZXIgJSAxMCA9PSAxKSB7CiAgICAgICAgJHdvcmQgPSAkd29yZDE7CiAgICB9IGVsc2VpZiAoJG51bWJlciAlIDEwID49IDIgJiYgJG51bWJlciAlIDEwIDw9IDQpIHsKICAgICAgICAkd29yZCA9ICR3b3JkMjsKICAgIH0gZWxzZWlmICgkbnVtYmVyICUgMTAgPj0gNSB8fCAkbnVtYmVyICUgMTAgPT0gMCkgewogICAgICAgICR3b3JkID0gJHdvcmQ1Owog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ICAgICRmZW1hbGVTcGVsbGluZyA9IGFycmF5KAogICAgICAgIDEgICA9PiAgJ9C+0LTQvdCwJywgICAgICAgIDIgICA9PiAgJ9C00LLQtScKICAgICk7CiAgICAKICAgIC8v0YfQuNGB0LvQsCDQv9GA0L7Qv9C40YHRjNGOINC00LvRjyDQutCw0LbQtNC+0LPQviDRgNCw0LfRgNGP0LTQsAogICAgJG51bWJlcnM9YXJyYXkoKTsKICAgIC8v0YfQuNGB0LvQsCDQv9GA0L7Qv9C40YHRjNGOINGB0YLRgNC+0LrQvtC5CiAgICAkdGV4dCA9ICcnOyAKICAgICAgIAogICAgLy/QtdGB0LvQuCDQsiDRh9C40YHQu9C1INC10YHRgtGMINGB0L7RgtC90LgsINC00L7QsdCw0LLQu9GP0LXQvCDRgdC70L7QstC+INC00LvRjyDRgdC+0YLQtdC9CiAgICBpZiAoJG51bWJlcj49MTAwKSB7CiAgICAgICAgJG51bWJlcnNbIjAiXSA9IChmbG9vcigkbnVtYmVyLzEwMCkpKjEwMDsKICAgICAgICAkbnVtYmVyc1siMCJdID0gJHNwZWxsaW5nWyRudW1iZXJzWzBdXTsgICAgICAgIAogICAgfQogICAgaWYgKDExIDw9ICRudW1iZXIgJSAxMDAgJiYgJG51bWJlciAlIDEwMCA8PSAxOSkgeyAvLy4uLiDRgdC70L7QstC+INC00LvRjyAxMS0xOSAgCiAgICAKICAgICAgICAkbnVtYmVyc1siMSJdID0gJG51bWJlciAlIDEwMDsgIAogICAgICAgICRudW1iZXJzWyIxIl0gPSAkc3BlbGxpbmdbJG51bWJlcnNbIjEiXV07CiAgICB9CiAgICBpZiAoMTAgPD0gJG51bWJlciAlIDEwMCAmJiAkbnVtYmVyICUgMTAwIDw9IDk5KSB7IC8vLi4uINGB0LvQvtCy0L4g0LTQtdGB0Y/RgtC60L7QsgogICAgICAgIAogICAgICAgICRudW1iZXJzWyIyIl0gPSBmbG9vcigoJG51bWJlciAlIDEwMCkvMTApKjEwOyAgCiAgICAgICAgJG51b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