Andy Bailey answered the age-old question on StackOverflow:
How do you convert a Roman numeral into an integer in PHP?
And the answer is, drumroll, please…
$romans = array( 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1, ); $roman = 'MMMCMXCIX'; $result = 0; foreach ($romans as $key => $value) { while (strpos($roman, $key) === 0) { $result += $value; $roman = substr($roman, strlen($key)); } } echo $result;
Thank you, Andy.