79502067

Date: 2025-03-11 20:46:00
Score: 1
Natty:
Report link

You might want to still use PHP's NumberFormatter and set the PARSE_INT_ONLY attribute. Here's its manual: https://www.php.net/manual/en/class.numberformatter.php. You can try something like this:

function romanToInt(string $roman) {
    static $nf = null;

    if ($nf === null) {
        $nf = new \NumberFormatter('@numbers=roman', \NumberFormatter::DECIMAL);
        $nf->setAttribute(\NumberFormatter::PARSE_INT_ONLY, true);
    }

    return $nf->parse($roman);
}
Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Berkay Kaplan