<?php
function returnText($number){
$numText = '';
$declinateArray = array();
$firstNumGroup = floor($number/1000000); // Бьем на миллионы
$declinateArray[0]['number'] = $firstNumGroup;
$declinateArray[0]['letter1'] = 'миллион';
$declinateArray[0]['letter2'] = 'миллиона';
$declinateArray[0]['letter3'] = 'миллионов';
$declinateArray[0]['isFemale'] = 0;
$secondNumGroup = floor(($number%1000000)/1000); // Бьем на тысячи
$declinateArray[1]['number'] = $secondNumGroup;
$declinateArray[1]['letter1'] = 'тысяча';
$declinateArray[1]['letter2'] = 'тысячи';
$declinateArray[1]['letter3'] = 'тысяч';
$declinateArray[1]['isFemale'] = 1;
$thirdNumGroup = $number%1000; // Бьем на сотни
$declinateArray[2]['number'] = $thirdNumGroup;
$declinateArray[2]['letter1'] = 'рубль';
$declinateArray[2]['letter2'] = 'рубля';
$declinateArray[2]['letter3'] = 'рублей';
$declinateArray[2]['isFemale'] = 0;
function declinateNumbers($number, $letter1, $letter2, $letter3){ //Прием цифры и 3 склонений слова
if($number == 0){
return;
}
$declinationNum = $number%10;
if($declinationNum == 1){
return $letter1;
}elseif($declinationNum == 2 || $declinationNum == 3 || $declinationNum == 4){
return $letter2;
}else{
return $letter3;
}
}
// $isFemale равен 0 когда слово мужского (миллион) рода и 1 когда женского (тысяча)
function getSmallNumber($number, $isFemale){
if($number == 0){
return;
}
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 >= 100){ // Находим трехзначные числа
$firstRoundNum = floor($number/100) * 100; $smallNumber[] = $spelling[$firstRoundNum];
}
$secondNum = $number%100; // Находим двузначные числа
if($secondNum < 20){ // В случае когда двузначные числа меньше 20
$smallNumber[] = $spelling[$secondNum]; // Находим единицы
}elseif($secondNum%10 == 0){ //Когда двузначное число заканчивается нулем
$smallNumber[] = $spelling[$secondNum];
}else{ //В случае когда двузначные числа >= 20
$secondRoundNum = floor($secondNum/10) * 10; $smallNumber[] = $spelling[$secondRoundNum];
$thirdRoundNum = $number%10;
if ($thirdRoundNum == 1 || $thirdRoundNum == 2 && $isFemale == 1){ // Проверка на тысячи
$smallNumber[] = $femaleSpelling[$thirdRoundNum];
}else{
$smallNumber[] = $spelling[$thirdRoundNum];
}
}
$smallText = implode(' ', $smallNumber); // Клеем массив пробелами return $smallText;
}
// Идем на 3 оборота чтоб прогнать разбитую на 3 части цифру по функциям
for($i = 0; $i < 3; $i++){
$numerToText = getSmallNumber($declinateArray[$i]['number'], $declinateArray[$i]['isFemale']);
$declination = declinateNumbers($declinateArray[$i]['number'], $declinateArray[$i]['letter1'], $declinateArray[$i]['letter2'], $declinateArray[$i]['letter3']);
$numText = $numText. $numerToText. ' '. $declination. ' ';
}
return $numText;
}
$numText = returnText($number);
print $numText;
PD9waHAKZnVuY3Rpb24gcmV0dXJuVGV4dCgkbnVtYmVyKXsKCSRudW1UZXh0ID0gJyc7CgkkZGVjbGluYXRlQXJyYXkgPSBhcnJheSgpOwoJCgkkZmlyc3ROdW1Hcm91cCA9IGZsb29yKCRudW1iZXIvMTAwMDAwMCk7IC8vINCR0YzQtdC8INC90LAg0LzQuNC70LvQuNC+0L3RiwoJCgkkZGVjbGluYXRlQXJyYXlbMF1bJ251bWJlciddID0gJGZpcnN0TnVtR3JvdXA7CgkkZGVjbGlu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