<?php
// Staring straight up into the sky ... oh my my
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
function inclineWord( $number ) {
$word5 = "" ;
$lastDigits = $number % 100 ;
$lastDigit = $lastDigits % 10 ;
if ( $lastDigit == 1 && $lastDigits != 11 ) {
$word5 = " рубль" ;
}
if ( $lastDigit > 1 && $lastDigit < 5 ) {
$word5 = " рубля" ;
}
if ( $lastDigit == 0 || ( $lastDigits > 10 && $lastDigits < 20 ) || ( $lastDigit > 4 && $lastDigit < 10 ) ) {
$word5 = " рублей" ;
}
return $word5 ;
}
/*
* Преобразует числа от 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 => 'девятнадцать'
) ;
$femaleSpelling = array ( 'одна ' ,
'две '
) ;
$arrNumber = [ ] ;
$word = "" ;
$arrNumber = preg_split ( "//" , $number , - 1 , PREG_SPLIT_NO_EMPTY
) ; $numberCount = count ( $arrNumber ) ; if ( $numberCount == 1 && $isFemale == 0 ) { // обрабатываем 1-9
$word = $spelling [ $arrNumber [ 0 ] ] ;
} else if ( $numberCount == 1 && $isFemale == 1 ) {
if ( $arrNumber [ 0 ] == 1 ) {
$word = $femaleSpelling [ 0 ] ;
}
}
if ( $numberCount == 2 && $isFemale == 0 ) { // обрабатываем 10-99
if ( $number > 10 && $number < 20 ) {
$word = $spelling [ $number ] ;
} else if ( $arrNumber [ 1 ] == 1 && $isFemale == 0 ) {
$word = $spelling [ ( $arrNumber [ 0 ] * 10 ) ] . " " . $spelling [ $arrNumber [ 1 ] ] ;
} else
$word = $spelling [ ( $arrNumber [ 0 ] * 10 ) ] . " " . $spelling [ $arrNumber [ 1 ] ] ;
} else if ( $numberCount == 2 && $isFemale == 1 ) {
if ( $arrNumber [ 1 ] == 1 ) {
$word = $spelling [ ( $arrNumber [ 0 ] * 10 ) ] . " " . $femaleSpelling [ 0 ] ;
} else
$word = $spelling [ ( $arrNumber [ 0 ] * 10 ) ] . " " . $femaleSpelling [ 1 ] ;
}
if ( $numberCount == 3 && $isFemale == 0 ) { // обрабатываем 100-999
$last = $arrNumber [ 1 ] . $arrNumber [ 2 ] ;
if ( $last > 10 && $last < 20 ) {
$word = $spelling [ ( $arrNumber [ 0 ] * 100 ) ] . " " . $spelling [ $last ] ;
} else
$word = $spelling [ ( $arrNumber [ 0 ] * 100 ) ] . " " . $spelling [ $arrNumber [ 1 ] * 10 ] . " " . $spelling [ $arrNumber [ 2 ] ] ;
} else if ( $numberCount == 3 && $isFemale == 1 ) {
$last = $arrNumber [ 1 ] . $arrNumber [ 2 ] ;
if ( $arrNumber [ 2 ] == 1 ) {
$word = $spelling [ ( $arrNumber [ 0 ] * 100 ) ] . " " . $spelling [ ( $arrNumber [ 1 ] * 10 ) ] . " " . $femaleSpelling [ 0 ] ;
} else
$word = $word = $spelling [ ( $arrNumber [ 0 ] * 100 ) ] . " " . $spelling [ ( $arrNumber [ 1 ] * 10 ) ] . " " . $femaleSpelling [ 1 ] ;
}
return $word ;
}
function numberToText( $number ) {
if ( $number == 0 ) {
return "ноль (0) рублей" ;
}
$thousandSpelling = [
" тысяча " ,
" тысячи " ,
" тысяч "
] ;
$millionSpelling = [
" миллион " ,
" миллиона " ,
" миллионов "
] ;
$numberArray = preg_split ( "//" , $number , - 1 , PREG_SPLIT_NO_EMPTY
) ; $numberArrayCount = count ( $numberArray ) ; $text = "" ;
if ( $number < 1000 ) {
$text = smallNumberToText ( $number , 0 ) . " ($number )" . inclineWord ( $number ) ;
}
if ( $numberArrayCount == 4 ) { // тысячи
$last = $numberArray [ 1 ] . $numberArray [ 2 ] . $numberArray [ 3 ] ;
if ( $numberArray [ 0 ] == 1 ) {
$text = smallNumberToText ( $numberArray [ 0 ] , 1 ) . $thousandSpelling [ 0 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 0 ] > 1 && $numberArray [ 0 ] < 5 ) {
$text = smallNumberToText ( $numberArray [ 0 ] , 1 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else
$text = smallNumberToText ( $numberArray [ 0 ] , 1 ) . $thousandSpelling [ 2 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
}
if ( $numberArrayCount == 5 ) { // десятки тысяч
$first = $numberArray [ 0 ] . $numberArray [ 1 ] ;
$last = $numberArray [ 2 ] . $numberArray [ 3 ] . $numberArray [ 4 ] ;
if ( $numberArray [ 1 ] == 1 ) {
$text = smallNumberToText ( $first , 1 ) . $thousandSpelling [ 0 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 1 ] == 2 ) {
$text = smallNumberToText ( $first , 1 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 1 ] > 2 && $numberArray [ 1 ] < 5 ) {
$text = smallNumberToText ( $first , 0 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else
$text = smallNumberToText ( $first , 0 ) . $thousandSpelling [ 2 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
}
if ( $numberArrayCount == 6 ) { // сотни тысяч
$first = $numberArray [ 0 ] . $numberArray [ 1 ] . $numberArray [ 2 ] ;
$last = $numberArray [ 3 ] . $numberArray [ 4 ] . $numberArray [ 5 ] ;
if ( $numberArray [ 2 ] == 1 ) {
$text = smallNumberToText ( $first , 1 ) . $thousandSpelling [ 0 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 2 ] == 2 ) {
$text = smallNumberToText ( $first , 1 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 2 ] > 2 && $numberArray [ 2 ] < 5 ) {
$text = smallNumberToText ( $first , 0 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else
$text = smallNumberToText ( $first , 0 ) . $thousandSpelling [ 2 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
}
if ( $numberArrayCount == 7 ) { // миллионы
$first = $numberArray [ 0 ] ;
$middle = $numberArray [ 1 ] . $numberArray [ 2 ] . $numberArray [ 3 ] ;
$last = $numberArray [ 4 ] . $numberArray [ 5 ] . $numberArray [ 6 ] ;
if ( $numberArray [ 3 ] == 1 ) {
$text = smallNumberToText ( $middle , 1 ) . $thousandSpelling [ 0 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 3 ] == 2 ) {
$text = smallNumberToText ( $middle , 1 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 3 ] > 2 && $numberArray [ 3 ] < 5 ) {
$text = smallNumberToText ( $middle , 0 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else
$text = smallNumberToText ( $middle , 0 ) . $thousandSpelling [ 2 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
if ( $numberArray [ 0 ] == 1 ) {
$text = smallNumberToText ( $first , 0 ) . " " . $millionSpelling [ 0 ] . $text ;
} else if ( $numberArray [ 0 ] > 1 && $numberArray [ 0 ] < 5 ) {
$text = smallNumberToText ( $first , 0 ) . " " . $millionSpelling [ 1 ] . $text ;
} else
$text = smallNumberToText ( $first , 0 ) . " " . $millionSpelling [ 2 ] . $text ;
}
if ( $numberArrayCount == 8 ) { // десятки миллионов
$first = $numberArray [ 0 ] . $numberArray [ 1 ] ;
$middle = $numberArray [ 2 ] . $numberArray [ 3 ] . $numberArray [ 4 ] ;
$last = $numberArray [ 5 ] . $numberArray [ 6 ] . $numberArray [ 7 ] ;
if ( $numberArray [ 4 ] == 1 ) {
$text = smallNumberToText ( $middle , 1 ) . $thousandSpelling [ 0 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 4 ] == 2 ) {
$text = smallNumberToText ( $middle , 1 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else if ( $numberArray [ 4 ] > 2 && $numberArray [ 4 ] < 5 ) {
$text = smallNumberToText ( $middle , 0 ) . $thousandSpelling [ 1 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
} else
$text = smallNumberToText ( $middle , 0 ) . $thousandSpelling [ 2 ] . smallNumberToText ( $last , 0 ) . " ($number )" . inclineWord ( $last ) ;
if ( $numberArray [ 1 ] == 1 ) {
$text = smallNumberToText ( $first , 0 ) . " " . $millionSpelling [ 0 ] . $text ;
} else if ( $numberArray [ 1 ] > 1 && $numberArray [ 1 ] < 5 ) {
$text = smallNumberToText ( $first , 0 ) . " " . $millionSpelling [ 1 ] . $text ;
} else
$text = smallNumberToText ( $first , 0 ) . " " . $millionSpelling [ 2 ] . $text ;
}
return $text ;
}
/* Вызовем функцию несколько раз */
$amount1 = mt_rand ( 1 , 99999999 ) ; $text1 = numberToText ( $amount1 ) ;
echo "На вашем счету {$text1} \n " ;
$amount2 = mt_rand ( 1 , 99999999 ) ; $text2 = numberToText ( $amount2 ) ;
echo "На вашем счету {$text2} \n " ;
$amount3 = mt_rand ( 1 , 99999999 ) ; $text3 = numberToText ( $amount3 ) ;
echo "На вашем счету {$text3} \n " ;
$amount4 = mt_rand ( 1 , 99999999 ) ; $text4 = numberToText ( $amount4 ) ;
echo "На вашем счету {$text4} \n " ;
PD9waHAKLy8gU3RhcmluZyBzdHJhaWdodCB1cCBpbnRvIHRoZSBza3kgLi4uIG9oIG15IG15CmVycm9yX3JlcG9ydGluZyAoIC0gMSApOwptYl9pbnRlcm5hbF9lbmNvZGluZyAoICd1dGYtOCcgKTsKCi8qINCS0L7Qt9Cy0YDQsNGJ0LDQtdGCINGB0L7QvtGC0LLQtdGC0YHRgtCy0YPRjtGJ0YPRjiDRh9C40YHQu9GDINGE0L7RgNC80YMg0YHQu9C+0LLQsDogMSDRgNGD0LHQu9GMLCAyINGA0YPQsdC70Y8sIDUg0YDRg9Cx0LvQtdC5ICovCmZ1bmN0aW9uIGluY2xpbmVXb3JkKCRudW1iZXIpIHsKCSR3b3JkNSA9ICIiOwoJJGxhc3REaWdpdHMgPSAkbnVtYmVyICUgMTAwOwoJJGxhc3REaWdpdCA9ICRsYXN0RGlnaXRzICUgMTA7CglpZiAoJGxhc3REaWdpdCA9PSAxICYmICRsYXN0RGlnaXRzICE9IDExKSB7CgkJJHdvcmQ1ID0gIiDRgNGD0LHQu9GMIjsKCX0KCWlmICgkbGFzdERpZ2l0ID4gMSAmJiAkbGFzdERpZ2l0IDwgNSkgewoJCSR3b3JkNSA9ICIg0YDRg9Cx0LvRjyI7Cgl9CglpZiAoJGxhc3REaWdp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