public static function toInt($roman)
    {
        if (!preg_match('`[MDCLXVI]+`', strtoupper($roman))) {
            throw new \InvalidArgumentException("$roman is an invalid roman numeral.");
        }
        $roman = strtoupper($roman);

        $characters = array_flip(self::$characters);

        $int = 0;
        while (strlen($roman) > 0) {
            if (isset($characters[substr($roman, 0, 2)])) {
                $int += $characters[substr($roman, 0, 2)];
                $roman = substr($roman, 2);
                continue;
            }
            if (isset($characters[substr($roman, 0, 1)])) {
                $int += $characters[substr($roman, 0, 1)];
                $roman = substr($roman, 1);
                continue;
            }
        }

        return $int;
    }
public static function toInt($roman)
    {
        if (!preg_match('`[MDCLXVI]+`', strtoupper($roman))) {
            throw new \InvalidArgumentException("$roman is an invalid roman numeral.");
        }
        $roman = strtoupper($roman);

        $characters = array_flip(self::$characters);

        $int = 0;
        while (strlen($roman) > 0) {
            if (isset($characters[substr($roman, 0, 2)])) {
                $int += $characters[substr($roman, 0, 2)];
                $roman = substr($roman, 2);
                continue;
            }
            if (isset($characters[substr($roman, 0, 1)])) {
                $int += $characters[substr($roman, 0, 1)];
                $roman = substr($roman, 1);
                continue;
            }
        }

        return $int;
    }
public static function toInt ( $ roman ) { if ( ! preg_match ( '`[MDCLXVI]+`' , strtoupper ( $ roman ) ) ) { throw new \ InvalidArgumentException ( "$roman is an invalid roman numeral." ) ; } $ roman = strtoupper ( $ roman ) ; $ characters = array_flip ( self :: $ characters ) ; $ int = 0 ; while ( strlen ( $ roman ) > 0 ) { if ( isset ( $ characters [ substr ( $ roman , 0 , 2 ) ] ) ) { $ int += $ characters [ substr ( $ roman , 0 , 2 ) ] ; $ roman = substr ( $ roman , 2 ) ; continue ; } if ( isset ( $ characters [ substr ( $ roman , 0 , 1 ) ] ) ) { $ int += $ characters [ substr ( $ roman , 0 , 1 ) ] ; $ roman = substr ( $ roman , 1 ) ; continue ; } } return $ int ; }
Convert a roman numeral to an integer.

@param string $roman

@return int
Convert a roman numeral to an integer .