public static function fromArbitraryBase(string $number, string $alphabet) : BigInteger
    {
        if ($number === '') {
            throw new NumberFormatException('The number cannot be empty.');
        }

        $base = \strlen($alphabet);

        if ($base < 2) {
            throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.');
        }

        $pattern = '/[^' . \preg_quote($alphabet, '/') . ']/';

        if (\preg_match($pattern, $number, $matches) === 1) {
            throw NumberFormatException::charNotInAlphabet($matches[0]);
        }

        $number = Calculator::get()->fromArbitraryBase($number, $alphabet, $base);

        return new BigInteger($number);
    }
public static function fromArbitraryBase(string $number, string $alphabet) : BigInteger
    {
        if ($number === '') {
            throw new NumberFormatException('The number cannot be empty.');
        }

        $base = \strlen($alphabet);

        if ($base < 2) {
            throw new \InvalidArgumentException('The alphabet must contain at least 2 chars.');
        }

        $pattern = '/[^' . \preg_quote($alphabet, '/') . ']/';

        if (\preg_match($pattern, $number, $matches) === 1) {
            throw NumberFormatException::charNotInAlphabet($matches[0]);
        }

        $number = Calculator::get()->fromArbitraryBase($number, $alphabet, $base);

        return new BigInteger($number);
    }
public static function fromArbitraryBase ( string $ number , string $ alphabet ) : BigInteger { if ( $ number === '' ) { throw new NumberFormatException ( 'The number cannot be empty.' ) ; } $ base = \ strlen ( $ alphabet ) ; if ( $ base < 2 ) { throw new \ InvalidArgumentException ( 'The alphabet must contain at least 2 chars.' ) ; } $ pattern = '/[^' . \ preg_quote ( $ alphabet , '/' ) . ']/' ; if ( \ preg_match ( $ pattern , $ number , $ matches ) === 1 ) { throw NumberFormatException :: charNotInAlphabet ( $ matches [ 0 ] ) ; } $ number = Calculator :: get ( ) -> fromArbitraryBase ( $ number , $ alphabet , $ base ) ; return new BigInteger ( $ number ) ; }
Parses a string containing an integer in an arbitrary base, using a custom alphabet.

Because this method accepts an alphabet with any character, including dash, it does not handle negative numbers.

@param string $number   The number to parse.
@param string $alphabet The alphabet, for example '01' for base 2, or '01234567' for base 8.

@return BigInteger

@throws NumberFormatException     If the given number is empty or contains invalid chars for the given alphabet.
@throws \InvalidArgumentException If the alphabet does not contain at least 2 chars.
Parses a string containing an integer in an arbitrary base using a custom alphabet .