<?php
# Transfer an integer to Roman numarals
# (1=I, 2=II, 5=V, 10=X, 50=L, 100=C, 500=D, 1000=M)
# Input: (1 to 3999)
#
function roman_numerals($number) {
    if ($number > 0 and $number <= 3999) {
        $rest = $number;
        $roman_numerals = '';
        while ($rest >= 1000) {
            $roman_numerals = $roman_numerals . 'M';
            $rest = $rest - 1000;
        }
        while ($rest >= 900) {
            $roman_numerals = trim($roman_numerals . 'CM');
            $rest = $rest - 900;
        }
        while ($rest >= 500) {
            $roman_numerals = trim($roman_numerals . 'D');
            $rest = $rest - 500;
        }
        while ($rest >= 400) {
            $roman_numerals = trim($roman_numerals . 'CD');
            $rest = $rest - 400;
        }
        while ($rest >= 100) {
            $roman_numerals = trim($roman_numerals . 'C');
            $rest = $rest - 100;
        }
        while ($rest >= 90) {
            $roman_numerals = trim($roman_numerals . 'XC');
            $rest = $rest - 90;
        }
        while ($rest >= 50) {
            $roman_numerals = trim($roman_numerals . 'L');
            $rest = $rest - 50;
        }
        while ($rest >= 40) {
            $roman_numerals = trim($roman_numerals . 'XL');
            $rest = $rest - 40;
        }
        while ($rest >= 10) {
            $roman_numerals = trim($roman_numerals . 'X');
            $rest = $rest - 10;
        }
        while ($rest >= 9) {
            $roman_numerals = trim($roman_numerals . 'IX');
            $rest = $rest - 9;
        }
        while ($rest >= 5) {
            $roman_numerals = trim($roman_numerals . 'V');
            $rest = $rest - 5;
        }
        while ($rest >= 4) {
            $roman_numerals = trim($roman_numerals . 'IV');
            $rest = $rest - 4;
        }
        while ($rest > 0) {
            $roman_numerals = trim($roman_numerals . 'I');
            $rest = $rest - 1;
        }
    }
    else
    {
$roman_numerals = 'Error: Input function roman_numarals() moet zijn >=0 en <= 3999!';
    }
    return $roman_numerals;
}
#echo roman_numerals(1999)
?>