<?php
header ( "Content-Type: text/plain" ) ;
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord( $number , $word ) {
if ( ( $number % 10 >= 5 ) |
( $number % 10 < 5 & $number % 100 < 21 ) ) {
$incline = 5 ;
} elseif ( ( $number % 10 == 2 & $number % 100 != 12 ) |
( $number % 10 == 3 & $number % 100 != 13 ) |
( $number % 10 == 4 & $number % 100 != 14 ) ) {
$incline = 2 ;
} elseif ( $number % 10 == 1 & $number % 100 != 11 ) {
$incline = 1 ;
}
if ( $incline == 5 ) {
} elseif ( $incline == 2 ) {
} elseif ( $incline == 1 ) {
} elseif ( $incline == 0 ) {
}
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 => 'две'
) ;
//нормализация числа
$number = ( $number / 100 ) * 100 ;
if ( $number >= 100 ) {
if ( ( $number % 100 ) == 0 ) {
$number000 = strtr ( $number , $spelling ) ; $text = $number000 ;
} else {
$number000 = ( floor ( $number / 100 ) ) * 100 ; $number000 = strtr ( $number000 , $spelling ) ;
$number00 = $number % 100 ;
if ( $number00 > 19 ) {
if ( ( $number % 10 ) == 0 ) {
$number00 = strtr ( $number00 , $spelling ) ; } else {
$number00 = ( floor ( $number00 / 10 ) ) * 10 ; $number00 = strtr ( $number00 , $spelling ) ;
$number0 = $number % 10 ;
if ( $isFemale == 1 & $number0 <= 2 ) {
$number0 = strtr ( $number0 , $femaleSpelling ) ; } else {
$number0 = strtr ( $number0 , $spelling ) ; }
$number00 = $number00 . " " . $number0 ;
}
} elseif ( $number00 <= 19 ) {
if ( $isFemale == 1 & $number00 <= 2 ) {
$number00 = strtr ( $number00 , $femaleSpelling ) ; } else {
$number00 = strtr ( $number00 , $spelling ) ; }
}
$number000 = $number000 . " " . $number00 ;
}
$text = $number000 ;
} elseif ( $number > 19 & $number < 100 ) {
if ( ( $number % 10 ) == 0 ) {
$number00 = strtr ( $number , $spelling ) ;
} else {
$number00 = ( floor ( $number / 10 ) ) * 10 ; $number00 = strtr ( $number00 , $spelling ) ;
$number0 = $number % 10 ;
if ( $isFemale == 1 & $number0 <= 2 ) {
$number0 = strtr ( $number0 , $femaleSpelling ) ; } else {
$number0 = strtr ( $number0 , $spelling ) ; }
$number00 = $number00 . " " . $number0 ;
}
$text = $number00 ;
} elseif ( $number <= 19 ) {
if ( $isFemale == 1 & $number <= 2 ) {
$number = strtr ( $number , $femaleSpelling ) ; } else {
$number = strtr ( $number , $spelling ) ; }
$text = $number ;
}
return $text ;
}
// проверяем чмсло на разрядность
function bitNumber ( $number ) {
$bitNumber = 1 ;
while ( $number >= 10 ) {
$number = $number / 10 ;
$bitNumber ++;
}
//echo "$bitNumber\n";
return $bitNumber ;
}
function numberToText( $number ) {
$text = "" ;
$bitNumber = bitNumber ( $number ) ; // определяем кол-во разрядов в числе
$position = 0 ; // текущее положение каретки = 0
// продолжаем вакханалию пока положение каретки < количества символов //1234567
if ( ( ( mb_strlen ( $number ) - $position ) % 3 ) == 0 ) { // кратно трем $len = 3 ;
} elseif ( mb_strlen ( $number ) < 3 ) { // меньше 1000 } elseif ( mb_strlen ( $number ) > 3 ) { // больше 1000 }
//отняимес слева $количество_символов -> переименовываем в согласно разряду
$pieceNumber = mb_substr ( $number , $position , $len ) ; $word = smallNumberToText( $pieceNumber , $bitNumber ) ;
// распределяем по порядку разрядов и добавляем миллион, тысяч и рублей
if ( $bitNumber >= 7 ) {
$word = smallNumberToText( $pieceNumber , 0 ) . " " . "миллион" ;
} elseif ( $bitNumber >= 4 ) {
$word = smallNumberToText( $pieceNumber , 1 ) . " " . "тысяча" ;
} elseif ( $bitNumber < 4 ) {
$word = smallNumberToText( $pieceNumber , 0 ) . " " . "рубль" ;
}
// отправляем число 265 в функция_склонения
$word = inclineWord( $pieceNumber , $word ) ;
//уменьшаем разряд на $количество отнятых символов
$bitNumber -= $len ;
//переводим каретку на + $количество_символов вправо
$position += $len ;
//Склеиваем строку
$text .= $word . " " ;
}
return $text ;
}
//Вызовем функцию несколько раз
$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 " ;
?>
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW4iKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CgogIAovKiDQktC+0LfQstGA0LDRidCw0LXRgiDRgdC+0L7RgtCy0LXRgtGB0YLQstGD0Y7RidGD0Y4g0YfQuNGB0LvRgyDRhNC+0YDQvNGDINGB0LvQvtCy0LA6IDEg0YDRg9Cx0LvRjCwgMiDRgNGD0LHQu9GPLCA1INGA0YPQsdC70LXQuSAqLwpmdW5jdGlvbiBpbmNsaW5lV29yZCgkbnVtYmVyLCAkd29yZCkgewogICAgCiAgICBpZiAoKCRudW1iZXIgJSAxMCA+PSA1KSB8IAogICAgICAgICgkbnVtYmVyICUgMTAgPCA1ICYgJG51bWJlciAlIDEwMCA8IDIxKSkgIHsKICAgICAgICAKICAgICAgICAkaW5jbGluZT01OwogICAgICAgIAogICAgfSBlbHNlaWYgKCgkbnVtYmVyICUgMTAgPT0gMiAmICRudW1iZXIgJSAxMDAgIT0gMTIpIHwKICAgICAgICAgICAgICAoJG51bWJlciAlIDEwID09IDMgJiAkbnVtYmVyICUgMTAwICE9IDEzKSB8CiAgICAgICAgICAgICAgKCRudW1iZXIgJSAxMCA9PSA0ICYgJG51bWJlciAlIDEwMCAhPSAxNCkpIHsKICAgICAgICAKICAgICAgICAkaW5jbGluZT0yOwogICAgICAgIAogICAgfSBlbHNlaWYgKCRudW1iZXIgJSAxMCA9PSAxICYgJG51bWJlciAlIDEwMCAhPSAxMSkgewogICAgICAgIAogICAgICAgICRpbmNsaW5lPTE7CiAgICB9CiAgICAKICAgIGlmICgkaW5jbGluZSA9PSA1ICkgIHsKICAgICAgICAkd29yZCA9IHN0cl9yZXBsYWNlKCfQvNC40LvQu9C40L7QvScsICfQvNC40LvQu9C40L7QvdC+0LInLCAkd29yZCk7CiAgICAgICAgJHdvcmQgPSBzdHJfcmVwbGFjZSgn0YLRi9GB0Y/Rh9CwJywgJ9GC0YvRgdGP0YcnLCAkd29yZCk7CiAgICAgICAgJHdvcmQgPSBzdHJfcmVwbGFjZSgn0YDRg9Cx0LvRjCcsICfRgNGD0LHQu9C10LknLCAkd29yZCk7CiAgICB9ICBlbHNlaWYgKCRpbmNsaW5lID09IDIgKSB7CiAgICAgICAgJHdvcmQgPSBzdHJfcmVwbGFjZSgn0LzQuNC70LvQuNC+0L0nLCAn0LzQuNC70LvQuNC+0L3QsCcsICR3b3JkKTsKICAgICAgICAkd29yZCA9IHN0cl9yZXBsYWNlKCfRgtGL0YHRj9GH0LAnLCAn0YLRi9GB0Y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PT4gICfRgdC10LzRjNC00LXRgdGP0YInLCAgICA3MDAgPT4gICfRgdC10LzRjNGB0L7RgicsICAgIAogICAgICAgIDcgICA9PiAgJ9GB0LXQvNGMJywgICAgICAgICAxNyAgPT4gICfRgdC10LzQvdCw0LTRhtCw0YLRjCcsICAgICAgIDgwICA9PiAgJ9Cy0L7RgdC10LzRjNC00LXRgdGP0YInLCAgIDgwMCA9PiAgJ9Cy0L7RgdC10LzRjNGB0L7RgicsCiAgICAgICAgOCAgID0+ICAn0LLQvtGB0LXQvNGMJywgICAgICAgMTggID0+ICAn0LLQvtGB0LXQvNC90LDQtNGG0LDRgtGMJywgICAgIDkwICA9PiAgJ9C00LXQstGP0L3QvtGB0YLQvicsICAgICA5MDAgPT4gICfQtNC10LLRj9GC0YzRgdC+0YInLAogICAgICAgIDkgICA9PiAgJ9C00LXQstGP0YLRjCcsICAgICAgIDE5ICA9PiAgJ9C00LXQstGP0YLQvdCw0LTRhtCw0YLRjCcgICAgCiAgICApOwogCiAgICAkZmVtYWxlU3BlbGxpbmcgPSBhcnJheSgKICAgICAgICAxICAgPT4gICfQvtC00L3QsCcsICAgICAgICAyICAgPT4gICfQtNCy0LUnCiAgICApOwogICAgIAogICAgLy/QvdC+0YDQvNCw0LvQuNC30LDRhtC40Y8g0YfQuNGB0LvQsAogICAgJG51bWJlciA9ICgkbnVtYmVyLzEwMCkqMTAwOwoKICAgIGlmICgkbnVtYmVyPj0xMDApIHsKICAgICAgICAKICAgICAgICBpZiAoKCRudW1iZXIgJSAxMDApPT0wKSB7CiAgICAgICAgICAgICRudW1iZXIwMDAgPSBzdHJ0cigkbnVtYmVyLCAkc3BlbGxpbmcpOyAKICAgICAgICAgICAgJHRleHQgPSAkbnVtYmVyMDAwOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIAogICAgICAgICAgICAkbnVtYmVyMDAwID0gKGZsb29yKCRudW1iZXIvMTAwKSkqMTAwOyAKICAgICAgICAgICAgJG51bWJlcjAwMCA9IHN0cnRyKCRudW1iZXIwMDAsICRzcGVsbGluZyk7IAogICAgICAgICAgICAKICAgICAgICAgICAgJG51bWJlcjAwID0gJG51bWJlciAlIDEwMDsKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmICgkbnVtYmVyMDA+MTkpIHsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaWYgKCgkbnVtYmVyICUgMTApPT0wKSB7CiAgICAgICAgICAgICAgICAgICAgJG51bWJlcjAwID0gc3RydHIoJG51bWJlcjAwLCAkc3BlbGxpbmcpOyAgICAgICAgICAgCiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICRudW1iZXIwMCA9IChmbG9vcigkbnVtYmVyMDAvMTApKSoxMDsgIAogICAgICAgICAgICAgICAgICAgICRudW1iZXIwMCA9IHN0cnRyKCRudW1iZXIwMCwgJHNwZWxsaW5nKTsKICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAkbnVtYmVyMCA9ICRudW1iZXIgJSAxMDsgCiAgICAgICAgICAgICAgICAgICAgaWYgKCRpc0ZlbWFsZT09MSAmICRudW1iZXIwIDw9MikgeyAKICAgICAgICAgICAgICAgICAgICAgICAgJG51bWJlcjAgPSBzdHJ0cigkbnVtYmVyMCwgJGZlbWFsZVNwZWxsaW5nKTsgCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgJG51bWJlcjAgPSBzdHJ0cigkbnVtYmVyMCwgJHNwZWxsaW5nKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgJG51bWJlcjAwID0gJG51bWJlcjAwIC4gIiAiIC4gJG51bWJlcjA7IAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgIH0gZWxzZWlmICgkbnVtYmVyMDA8PTE5KSB7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGlmICgkaXNGZW1hbGU9PTEgJiAkbnVtYmVyMDAgPD0yKSB7CiAgICAgICAgICAgICAgICAgICAgJG51bWJlcjAwID0gc3RydHIoJG51bWJlcjAwLCAkZmVtYWxlU3BlbGxpbmcpOyAKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgJG51bWJlcjAwID0gc3RydHIoJG51bWJlcjAwLCAkc3BlbGxpbmcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICAkbnVtYmVyMDAwID0gJG51bWJlcjAwMCAuICIgIiAuICRudW1iZXIwMDsKICAgICAgICB9CiAgICAgICAgJHRleHQgPSAkbnVtYmVyMDAwIDsKICAgIAogICAgfWVsc2VpZiAoJG51bWJlcj4xOSAmICRudW1iZXI8MTAwKSB7CiAgICAgICAgCiAgICAgICAgaWYgKCgkbnVtYmVyICUgMTApPT0wKSB7CiAgICAgICAgICAgICRudW1iZXIwMCA9IHN0cnRyKCRudW1iZXIsICRzcGVsbGluZyk7IAogICAgICAgICAgICAKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAkbnVtYmVyMDAgPSAoZmxvb3IoJG51bWJlci8xMCkpKjEwOwogICAgICAgICAgICAkbnVtYmVyMDAgPSBzdHJ0cigkbnVtYmVyMDAsICRzcGVsbGluZyk7CiAgICAgICAgICAgIAogICAgICAgICAgICAkbnVtYmVyMCA9ICRudW1iZXIgJSAxMDsKICAgICAgICAgICAgaWYgKCRpc0ZlbWFsZT09MSAmICRudW1iZXIwIDw9MikgewogICAgICAgICAgICAgICAkbnVtYmVyMCA9IHN0cnRyKCRudW1iZXIwLCAkZmVtYWxlU3BlbGxpbmcpOyAKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICRudW1iZXIwID0gc3RydHIoJG51bWJlcjAsICRzcGVsbGluZyk7CiAgICAgICAgICAgIH0gICAgICAKICAgICAgICAgICAgJG51bWJlcjAwID0gJG51bWJlcjAwIC4gIiAiIC4gJG51bWJlcjA7IAogICAgICAgIH0gICAgICAgCiAgICAgICAgJHRleHQgPSAkbnVtYmVyMDA7IAogICAgICAgIAogICAgfSBlbHNlaWYgKCRudW1iZXI8PTE5KSB7CiAgICAgICAgCiAgICAgICAgaWYgKCRpc0ZlbWFsZT09MSAmICRudW1iZXIgPD0yKSB7CiAgICAgICAgICAgICRudW1iZXIgPSBzdHJ0cigkbnVtYmVyLCAkZmVtYWxlU3BlbGxpbmcpOyAKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAkbnVtYmVyID0gc3RydHIoJG51bWJlciwgJHNwZWxsaW5nKTsKICAgICAgICB9CiAgICAgICAgJHRleHQgPSAkbnVtYmVyOyAKICAgIH0KICAgIHJldHVybiAkdGV4dDsKfQoKLy8g0L/RgNC+0LLQtdGA0Y/QtdC8INGH0LzRgdC70L4g0L3QsCDRgNCw0LfRgNGP0LTQvdC+0YHRgtGMCmZ1bmN0aW9uIGJpdE51bWJlciAoJG51bWJlcikgewogICAgJGJpdE51bWJlciA9IDE7ICAgIAogICAgd2hpbGUgKCRudW1iZXI+PTEwKSB7CiAgICAgICAgJG51bWJlciA9ICRudW1iZXIvMTA7IAogICAgICAgICRiaXROdW1iZXIrKzsKICAgIH0KICAgIC8vZWNobyAiJGJpdE51bWJlclxuIjsKICAgIHJldHVybiAkYml0TnVtYmVyOwp9CgpmdW5jdGlvbiBudW1iZXJUb1RleHQoJG51bWJlcikgewogICAgCiAgICAkdGV4dD0iIjsKICAgICRiaXROdW1iZXIgPSBiaXROdW1iZXIgKCRudW1iZXIpOyAvLyDQvtC/0YDQtdC00LXQu9GP0LXQvCDQutC+0Lst0LLQviDRgNCw0LfRgNGP0LTQvtCyINCyINGH0LjRgdC70LUgICAKICAgICRwb3NpdGlvbiA9IDA7ICAvLyDRgtC10LrRg9GJ0LXQtSDQv9C+0LvQvtC20LXQvdC40LUg0LrQsNGA0LXRgtC60LggPSAwCiAgICAKICAgIC8vINC/0YDQvtC00L7Qu9C20LDQtdC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