<?php
// Staring straight up into the sky ... oh my my
/* Возвращает соответствующую числу форму слова: 1 рубль, 2 рубля, 5 рублей */
//function inclineWord($number, $word1, $word2, $word5) {
function inclineWord($number) {
if (($number % 100 >= 10) && ($number % 100 <= 20)) {
$number = " рублей";
}
elseif (($number % 10 == 0) || ($number % 10 >= 5)) {
$number = " рублей";
}
elseif (($number % 10 >= 2) && ($number % 10 <= 4)) {
$number = " рубля";
}
else {
$number = " рубль";
}
return $number;
}
/*
Преобразует числа от 0 до 999 в текст. Параметр $isFemale равен нулю,
если мы считаем число для мужского рода (один рубль),
и 1 — для женского (одна тысяча)
*/
//function smallNumberToText($number, $isFemale) {
function smallNumberToText($number) {
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 => 'девятнадцать'
);
if ($number >= 1000000) {
$million = floor($number / 1000000); $x = $number % 1000000;
$thousand = floor($x / 1000); $hundred = $number % 1000;
$arr = array($million, $thousand, $hundred); if (($million % 100 >= 10) && ($million % 100 <= 20)) {
$mill = " миллионов";
}
elseif (($million % 10 == 1) || ($million % 10 >= 5)) {
$mill = " миллионов";
}
elseif (($million % 10 >= 2) && ($million % 10 <= 4)) {
$mill = " миллиона";
}
else {
$mill = " миллион";
}
//var_dump($arr);
}
elseif ($number >= 1000) {
$thousand = floor($number / 1000); $hundred = $number % 1000;
$arr = array($thousand, $houndred); $numb = ' тысяч ';
// var_dump($arr);
}
foreach ($arr as $value) {
if ($value >= 100) {
$mod = $value % 100;
$sotni = $value - $mod;
//$value = $spelling[$sotni];
$mod2 = $value % 10;
$desyatki = $mod - $mod2;
$word = $word . ' ' . $spelling[$sotni] . ' ' . $spelling[$desyatki] . ' ' . $spelling[$mod2];
}
elseif ($value > 9) {
$mod = $value % 10;
$sotni = $value - $mod;
//$value = $spelling[$sotni];
$desyatki = $mod - $mod2;
$word = $word . ' ' . $spelling[$mod];
}
else {
$word = $word . $spelling[$value];
}
}
$number = $word;
return $number;
/*
$femaleSpelling = array(
1 => 'одна', 2 => 'две'
);
*/
}
function numberToText($number) {
$number = smallNumberToText($number) . ' ' . '(' . $number . ')' . inclineWord($number);
return $number;
}
$amount0 = 3222777;
//$amount0 = splitNumber($amount0);
$text0 = numberToText($amount0);
echo "На вашем счету {$text0}\n";
/*
/* Вызовем функцию несколько раз */
// $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";
PD9waHAKIAovLyBTdGFyaW5nIHN0cmFpZ2h0IHVwIGludG8gdGhlIHNreSAuLi4gb2ggbXkgbXkKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7Ci8qINCS0L7Qt9Cy0YDQsNGJ0LDQtdGCINGB0L7QvtGC0LLQtdGC0YHRgtCy0YPRjtGJ0YPRjiDRh9C40YHQu9GDINGE0L7RgNC80YMg0YHQu9C+0LLQsDogMSDRgNGD0LHQu9GMLCAyINGA0YPQsdC70Y8sI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gewogICAgZnVuY3Rpb24gc21hbGxOdW1iZXJUb1RleHQoJG51bWJlcikgewogICAgICAgICRzcGVsbGluZyA9IGFycmF5KAogICAgICAgIDAgICA9PiAgJ9C90L7Qu9GMJywgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTAgID0+ICAn0LTQtdGB0Y/RgtGMJywgICAgICAgMTAwID0+ICAn0YHRgtC+JywKICAgICAgICAxICAgPT4gICfQvtC00LjQvScsICAgICAgICAgMTEgID0+ICAn0L7QtNC40L3QvdCw0LTRhtCw0YLRjCcsICAgICAgMjAgID0+ICAn0LTQstCw0LTRhtCw0YLRjCcsICAgICAyMDAgPT4gICfQtNCy0LXRgdGC0LgnLAogICAgICAgIDIgICA9PiAgJ9C00LLQsCcsICAgICAgICAgIDEyICA9PiAgJ9C00LLQtdC90LDQtNGG0LDRgtGMJywgICAgICAgMzAgID0+ICAn0YLRgNC40LTRhtCw0YLRjCcsICAgICAzMDAgPT4gICfRgtGA0LjRgdGC0LAnLAogICAgICAgIDMgICA9PiAgJ9GC0YDQuCcsICAgICAgICAgIDEzICA9PiAgJ9GC0YDQuNC90LDQtNGG0LDRgtGMJywgICAgICAgNDAgID0+ICAn0YHQvtGA0L7QuicsICAgICAgICA0MDAgPT4gICfRh9C10YLRi9GA0LXRgdGC0LAnLAogICAgICAgIDQgICA9PiAgJ9GH0LXRgtGL0YDQtScsICAgICAgIDE0ICA9PiAgJ9GH0LXRgtGL0YDQvdCw0LTRhtCw0YLRjCcsICAgICA1MCAgPT4gICfQv9GP0YLRjNC00LXRgdGP0YInLCAgICA1MDAgPT4gICfQv9GP0YLRjNGB0L7RgicsCiAgICAgICAgNSAgID0+ICAn0L/Rj9GC0YwnLCAgICAgICAgIDE1ICA9PiAgJ9C/0Y/RgtC90LDQtNGG0LDRgtGMJywgICAgICAgNjAgID0+ICAn0YjQtdGB0YLRjNC00LXRgdGP0YInLCAgIDYwMCA9PiAgJ9GI0LXRgdGC0YzRgdC+0YInLAogICAgICAgIDYgICA9PiAgJ9GI0LXRgdGC0YwnLCAgICAgICAgMTYgID0+ICAn0YjQtdGB0YLQvdCw0LTRhtCw0YLRjCcsICAgICAgNzAgID0+ICAn0YHQtdC80YzQtNC10YHRj9GCJywgICAgNzAwID0+ICAn0YHQtdC80YzRgdC+0YInLCAgICAKICAgICAgICA3ICAgPT4gICfRgdC10LzRjCcsICAgICAgICAgMTcgID0+ICAn0YHQtdC80L3QsNC00YbQsNGC0YwnLCAgICAgICA4MCAgPT4gICfQstC+0YHQtdC80YzQtNC10YHRj9GCJywgICA4MDAgPT4gICfQstC+0YHQtdC80YzRgdC+0YInLAogICAgICAgIDggICA9PiAgJ9Cy0L7RgdC10LzRjCcsICAgICAgIDE4ICA9PiAgJ9Cy0L7RgdC10LzQvdCw0LTRhtCw0YLRjCcsICAgICA5MCAgPT4gICfQtNC10LLRj9C90L7RgdGC0L4nLCAgICAgOTAwID0+ICAn0LTQtdCy0Y/RgtGM0YHQvtGCJywKICAgICAgICA5ICAgPT4gICfQtNC10LLRj9GC0YwnLCAgICAgICAxOSAgPT4gICfQtNC10LLRj9GC0L3QsNC00YbQsNGC0YwnICAgIAogICAgICAgICk7CiAKICAgICAgICAkYXJyID0gYXJyYXkoKTsKICAgICAgICAKICAgICAgICBpZiAoJG51bWJlciA+PSAxMDAwMDAwKSB7CiAgICAJCSRtaWxsaW9uID0gZmxvb3IoJG51bWJlciAvIDEwMDAwMDApOwogICAgICAgICAgICAkeCA9ICRudW1iZXIgJSAxMDAwMDAwOwogICAgICAgICAgICAkdGhvdXNhbmQgPSBmbG9vcigkeCAvIDEwMDApOwogICAgICAgICAgICAkaHVuZHJlZCA9ICRudW1iZXIgJSAxMDAwOwogICAgICAgICAgICAkYXJyID0gYXJyYXkoJG1pbGxpb24sICR0aG91c2FuZCwgJGh1bmRyZWQpOwogICAgICAgICAgICBpZiAoKCRtaWxsaW9uICUgMTAwID49IDEwKSAmJiAoJG1pbGxpb24gJSAxMDAgPD0gMjApKSB7CiAgICAgICAgJG1pbGwgPSAiINC80LjQu9C70LjQvtC90L7QsiI7CiAgICB9CiAgICBlbHNlaWYgKCgkbWlsbGlvbiAlIDEwID09IDEpIHx8ICgkbWlsbGlvbiAlIDEwID49IDUpKSB7CiAgICAgCSRtaWxsID0gIiDQvNC40LvQu9C40L7QvdC+0LIiOwogICAgfQogICAgZWxzZWlmICgoJG1pbGxpb24gJSAxMCA+PSAyKSAmJiAoJG1pbGxpb24gJSAxMCA8PSA0KSkgewogICAgICAJJG1pbGwgPSAiINC80LjQu9C70LjQvtC90LAiOwogICAgfQogICAgZWxzZSB7CiAgICAgCSRtaWxsID0gIiDQvNC40LvQu9C40L7QvSI7CiAgICB9CiAgICAgICAgCiAgICAgICAgICAgIC8vdmFyX2R1bXAoJGFycik7CiAgICAgICAgfQogCiAgICAJZWxzZWlmICgkbnVtYmVyID49IDEwMDApIHsKICAgIAkJJHRob3VzYW5kID0gZmxvb3IoJG51bWJlciAvIDEwMDApOwogICAgCQkkaHVuZHJlZCA9ICRudW1iZXIgJSAxMDAwOwogICAgCQkkYXJyID0gYXJyYXkoJHRob3VzYW5kLCAkaG91bmRyZWQpOyAKICAgIAkJJG51bWIgPSAnINGC0YvRgdGP0YcgJzsKICAgIAkJLy8gdmFyX2R1bXAoJGFycik7CiAgICAgICAgICAgICAJCiAgICAJfQogICAgICAgIAogICAgICAgIGZvcmVhY2ggKCRhcnIgYXMgJHZhbHVlKSB7CiAgICAgICAgICAgIGlmICgkdmFsdWUgPj0gMTAwKSB7CiAgICAgICAgICAgICAgICAkbW9kID0gJHZhbHVlICUgMTAwOwogICAgICAgICAgICAgICAgJHNvdG5pID0gJHZhbHVlIC0gJG1vZDsKICAgICAgICAgICAgICAgIC8vJHZhbHVlID0gJHNwZWxsaW5nWyRzb3RuaV07CiAgICAgICAgICAgICAgICAkbW9kMiA9ICR2YWx1ZSAlIDEwOwogICAgICAgICAgICAgICAgJGRlc3lhdGtpID0gJG1vZCAtICRtb2QyOwogICAgICAgICAgICAgICAgJHdvcmQgPSAkd29yZCAuICcgJyAuICRzcGVsbGluZ1skc290bmldIC4gJyAnIC4gJHNwZWxsaW5nWyRkZXN5YXRraV0gLiAnICcgLiAkc3BlbGxpbmdbJG1vZDJdOwogICAgICAgICAgICAgICAgCiAgICAgICAgICAgIH0gCiAgICAgICAgICAgIGVsc2VpZiAoJHZhbHVlID4gOSkgewogICAgICAgIAkgICAgJG1vZCA9ICR2YWx1ZSAlIDEwOwogICAgICAgICAgICAgICAgJHNvdG5pID0gJHZhbHVlIC0gJG1vZDsKICAgICAgICAgICAgICAgIC8vJHZhbHVlID0gJHNwZWxsaW5nWyRzb3RuaV07CiAgICAgICAgICAgICAgICAkZGVzeWF0a2kgPSAkbW9kIC0gJG1vZDI7CiAgICAgICAgICAgICAgICAkd29yZCA9ICR3b3JkIC4gJyAnIC4gJHNwZWxsaW5nWyRtb2RdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAJJHdvcmQgPSAkd29yZCAuICRzcGVsbGluZ1skdmFsdWVdOwogICAgICAgICAgICB9IAogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgJG51bWJlciA9ICR3b3JkOwogICAgICAgIHJldHVybiAkbnVtYmVyOwogICAgICAgIAogICAgICAgIC8qCiAgICAgICAgICAgJGZlbWFsZVNwZWxsaW5nID0gYXJyYXkoCiAgICAgICAgICAgICAgICAxICAgPT4gICfQvtC00L3QsCcsICAgICAgICAyICAgPT4gICfQtNCy0LUnCiAgICAgICAgICAgICk7CiAgICAgICAgICovCiAgICB9CiAKICAgIGZ1bmN0aW9uIG51bWJlclRvVGV4dCgkbnVtYmVyKSB7CiAKICAgICAgICAkbnVtYmVyID0gc21hbGxOdW1iZXJUb1RleHQoJG51bWJlcikgLiAnICcgLiAnKCcgLiAkbnVtYmVyIC4gJyknIC4gaW5jbGluZVdvcmQoJG51bWJlcik7CiAgICAgICAgcmV0dXJuICRudW1iZXI7CiA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