<?php
//$number = 301;
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 => 'девятнадцать'
);
'рубля' => array(2, 3, 4), 'рублей' => array(0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900) );
function findMatches($num, $spelling) {
$result = 0;
foreach ($spelling as $keys => $values) {
if ($num == $keys) {
$result = $values;
break;
}
} return $result;
}
function findRoublesForm($num, $roubles) {
$rouble = 0;
foreach ($roubles as $form => $numerals) {
foreach ($numerals as $s => $numeral) {
if ($num == $numeral) {
$rouble = $form;
}
}
} return $rouble;
}
function smallNumberToText($number, $spelling, $roubles) {
$i = 0;
$o = 0;
foreach ($spelling as $keys => $values) {
if ($number == $keys) {
$splash = $values;
$o++;
break;
}
}
$num = $number;
$rouble = findRoublesForm($num, $roubles);
if ($o > 0) {
$numberInWords = $splash.' '.$rouble;
} else {
if ($countLetters == 3) {
$firstNumberOfTheHundred = mb_substr($text, 0, 1); $findHundredEqual = (int)$firstNumberOfTheHundred * 100;
if ($findHundredEqual == 0) {
} else {
$num = $findHundredEqual;
$hundred = findMatches($num, $spelling);
$rouble = findRoublesForm($num, $roubles);
}
$findLastTwoNumerals = mb_substr($text, 1, 2); $lastTwoNumerals = (int)$findLastTwoNumerals;
foreach ($spelling as $keys => $values) {
if ($lastTwoNumerals == $keys) {
$ten = $values;
$i++;
break;
}
}
$num = $lastTwoNumerals;
$rouble = findRoublesForm($num, $roubles);
if ($i > 0) {
$numberInWords = $hundred.' '.$ten.' '.$rouble;
} else {
$firstNumberOfTheTen = mb_substr($text, 1, 1); $findTenEqual = (int)$firstNumberOfTheTen * 10;
if ($findTenEqual == 0) {
} else {
$num = $findTenEqual;
$ten = findMatches($num, $spelling);
}
$findLastOneNumeral = (int)$lastOneNumeral;
$num = $findLastOneNumeral;
$one = findMatches($num, $spelling);
$rouble = findRoublesForm($num, $roubles);
$numberInWords = $hundred.' '.$ten.' '.$one.' '.$rouble;
}
}
if ($countLetters == 2) {
$i = 0;
$twoNumerals = (int)$lastTwoNumerals;
foreach ($spelling as $keys => $values) {
if ($twoNumerals == $keys) {
$ten = $values;
$i++;
break;
}
}
$num = $twoNumerals;
$rouble = findRoublesForm($num, $roubles);
if ($i > 0) {
$numberInWords = $hundred.' '.$ten.' '.$rouble;
} else {
$firstNumeralOfTheTen = mb_substr($text, 0, 1); $tenEqual = (int)$firstNumeralOfTheTen * 10;
if ($tenEqual == 0) {
} else {
$num = $tenEqual;
$ten = findMatches($num, $spelling);
}
$findLastNumeral = (int)$lastNumeral;
$num = $findLastNumeral;
$one = findMatches($num, $spelling);
$rouble = findRoublesForm($num, $roubles);
$numberInWords = $ten.' '.$one.' '.$rouble;
}
}
}
return $numberInWords;
}
$cheking = smallNumberToText($number, $spelling, $roubles);
echo "\"{$number}\" - это \"{$cheking}\".";
?>
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Cm1iX2ludGVybmFsX2VuY29kaW5nKCdVVEYtOCcpOwoKLy8kbnVtYmVyID0gMzAxOwogICAgJHNwZWxsaW5nID0gYXJyYXkoCiAgICAgICAgMCAgID0+ICAn0L3QvtC70YwnLCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg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AgICBpZiAoJGZpbmRIdW5kcmVkRXF1YWwgPT0gMCkgewogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICRudW0gPSAkZmluZEh1bmRyZWRFcXVhbDsKICAgICAgICAgICAgICAgICAgICAkaHVuZHJlZCA9IGZpbmRNYXRjaGVzKCRudW0sICRzcGVsbGluZyk7CiAgICAgICAgICAgICAgICAgICAgJHJvdWJsZSA9IGZpbmRSb3VibGVzRm9ybSgkbnVtLCAkcm91Ymxlcyk7CiAgICAgICAgICAgICAgfQogICAgICAgICRmaW5kTGFzdFR3b051bWVyYWxzID0gbWJfc3Vic3RyKCR0ZXh0LCAxLCAyKTsKICAgICAgICAkbGFzdFR3b051bWVyYWxzID0gKGludCkkZmluZExhc3RUd29OdW1lcmFsczsKICAgICAgICBmb3JlYWNoICgkc3BlbGxpbmcgYXMgJGtleXMgPT4gJHZhbHVlcykgewogICAgICAgICAgICBpZiAoJGxhc3RUd29OdW1lcmFscyA9PSAka2V5cykgewogICAgICAgICAgICAJJHRlbiA9ICR2YWx1ZXM7CgkgICAgICAgICAgICAkaSsrOwoJICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0gCiAgICAgICAgfQogICAgICAgICRudW0gPSAkbGFzdFR3b051bWVyYWxzOwogICAgICAgICRyb3VibGUgPSBmaW5kUm91Ymxlc0Zvcm0oJG51bSwgJHJvdWJsZXMpOwogICAgICAgIGlmICgkaSA+IDApIHsKICAgICAgICAgICAgJG51bWJlckluV29yZHMgPSAkaHVuZHJlZC4nICcuJHRlbi4nICcuJHJvdWJsZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICRmaXJzdE51bWJlck9mVGhlVGVuID0gbWJfc3Vic3RyKCR0ZXh0LCAxLCAxKTsKICAgICAgICAkZmluZFRlbkVxdWFsID0gKGludCkkZmlyc3ROdW1iZXJPZlRoZVRlbiAqIDEwOwogICAgICAgIGlmICgkZmluZFRlbkVxdWFsID09IDApIHsKICAgICAgICB9IGVsc2UgewogICAgICAgIAkkbnVtID0gJGZpbmRUZW5FcXVhbDsKICAgICAgICAJJHRlbiA9IGZpbmRNYXRjaGVzKCRudW0sICRzcGVsbGluZyk7CiAgICAgICAgICAgIAogICAgICAgICAgfQogICAgICAgICRsYXN0T25lTnVtZXJhbCA9IG1iX3N1YnN0cigkdGV4dCwgMiwgMSk7CiAgICAgICAgJGZpbmRMYXN0T25lTnVtZXJhbCA9IChpbnQpJGxhc3RPbmVOdW1lcmFsOwogICAgICAgICRudW0gPSAkZmluZExhc3RPbmVOdW1lcmFsOwogICAgICAgICRvbmUgPSBmaW5kTWF0Y2hlcygkbnVtLCAkc3BlbGxpbmcpOwogICAgICAgICRyb3VibGUgPSBmaW5kUm91Ymxlc0Zvcm0oJG51bSwgJHJvdWJsZXMpOwogICAgICAgICRudW1iZXJJbldvcmRzID0gJGh1bmRyZWQuJyAnLiR0ZW4uJyAnLiRvbmUuJyAnLiRyb3VibGU7CiAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaWYgKCRjb3VudExldHRlcnMgPT0gMikgewogICAgICAgIAkkaSA9IDA7CiAgICAgICAgCSAgICAkbGFzdFR3b051bWVyYWxzID0gbWJfc3Vic3RyKCR0ZXh0LCAwLCAyKTsKICAgICAgICAgICAgICAgICR0d29OdW1lcmFscyA9IChpbnQpJGxhc3RUd29OdW1lcmFsczsKICAgICAgICAgICAgICAgIGZvcmVhY2ggKCRzcGVsbGluZyBhcyAka2V5cyA9PiAkdmFsdWVzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKCR0d29OdW1lcmFscyA9PSAka2V5cykgewoJICAgICAgICAgICAgICAgICR0ZW4gPSAkdmFsdWVzOwoJICAgICAgICAgICAgICAgICRpKys7CgkgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfSAKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICRudW0gPSAkdHdvTnVtZXJhbHM7CiAgICAgICAgICAgICAgICAkcm91YmxlID0gZmluZFJvdWJsZXNGb3JtKCRudW0sICRyb3VibGVzKTsKICAgICAgICBpZiAoJGkgPiAwKSB7CiAgICAgICAgICAgICRudW1iZXJJbldvcmRzID0gJGh1bmRyZWQuJyAnLiR0ZW4uJyAnLiRyb3VibGU7IAogICAgICAgIH0gZWxzZSB7CiAgICAgICAgJGZpcnN0TnVtZXJhbE9mVGhlVGVuID0gbWJfc3Vic3RyKCR0ZXh0LCAwLCAxKTsKICAgICAgICAkdGVuRXF1YWwgPSAoaW50KSRmaXJzdE51bWVyYWxPZlRoZVRlbiAqIDEwOyAKICAgICAgICBpZiAoJHRlbkVxdWFsID09IDApIHsKICAgICAgICB9IGVsc2UgewogICAgICAgIAkkbnVtID0gJHRlbkVxdWFsOwogICAgICAgIAkkdGVuID0gZmluZE1hdGNoZXMoJG51bSwgJHNwZWxsaW5nKTsKICAgICAgICAgIH0KICAgICAgICAkbGFzdE51bWVyYWwgPSBtYl9zdWJzdHIoJHRleHQsIDEsIDEpOwogICAgICAgICRmaW5kTGFzdE51bWVyYWwgPSAoaW50KSRsYXN0TnVtZXJhbDsKICAgICAgICAkbnVtID0gJGZpbmRMYXN0TnVtZXJhbDsKICAgICAgICAkb25lID0gZmluZE1hdGNoZXMoJG51bSwgJHNwZWxsaW5nKTsKICAgICAgICAkcm91YmxlID0gZmluZFJvdWJsZXNGb3JtKCRudW0sICRyb3VibGVzKTsKICAgICAgICAkbnVtYmVySW5Xb3JkcyA9ICR0ZW4uJyAnLiRvbmUuJyAnLiRyb3VibGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuICRudW1iZXJJbldvcmRzOwp9CgokbnVtYmVyID0gbXRfcmFuZCgxLDk5OSk7CiRjaGVraW5nID0gc21hbGxOdW1iZXJUb1RleHQoJG51bWJlciwgJHNwZWxsaW5nLCAkcm91Ymxlcyk7CmVjaG8gIlwieyRudW1iZXJ9XCIgLSDRjdGC0L4gXCJ7JGNoZWtpb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