@param string $isbn The ISBN-10, unformatted, regexp-validated.

@return string
557825
public static function convertIsbn10to13(string $isbn) : string
    {
        $isbn = '978' . substr($isbn, 0, 9);

        return $isbn . CheckDigit::calculateCheckDigit13($isbn);
    }
469908
def valid? number
      raise_on_type_mismatch number
      num, check = split_isbn_number(number)
      convert_number_to_digits(num).length == 9 && self.of(num) == check
    end
210059
public static function withCheckDigitForIsbn10($isbn)
    {
        // Sanitize
        $isbn = preg_replace('/[^0-9]/', '', $isbn);
        $isbn = substr($isbn, 0, 9);

        // Validate
        if (strlen($isbn) != 9) {
            return null;
        }

        // Calculate (sum)
        $sum = 0;
        for ($i = 0; $i < 9; $i++) {
            $sum += (10 - $i) * $isbn{$i};
        }

        // Calculate (check digit)
        $checkDigit = 11 - ($sum % 11);
        $checkDigit = $checkDigit == 10 ? "X" : ($checkDigit == 11 ? 0 : $checkDigit);

        return $isbn . $checkDigit;
    }
1037926
public static String isbn10Format(final String pstring) {
    if (pstring == null) {
      return null;
    }
    final ValueWithPos<String> formatedValue = isbn10FormatWithPos(new ValueWithPos<>(pstring, -1));
    return formatedValue.getValue();
  }
707600
private function validateIsbn10(): bool
    {
        $value = \str_replace(['-', ' '], '', $this->value);
        if (!\preg_match($this->patterns['isbn10-basic'], $value)) {
            $this->setError(self::VALIDATOR_ERROR_ISBN_INCORRECT_FORMAT);
            return false;
        }

        $sum = 0;
        for ($i = 0; $i < 9; $i++) {
            $sum += (10 - $i) * $value{$i};
        }

        $checksum = 11 - ($sum % 11);
        if ($checksum == 11) {
            $checksum = '0';
        } elseif ($checksum == 10) {
            $checksum = 'X';
        }
        $isValid = \substr($value, -1) == $checksum ? true : false;
        if (!$isValid) {
            $this->setError(self::VALIDATOR_ERROR_ISBN_INVALID_NUMBER);
        }
        return $isValid;
    }
1008028
static function convertISBN10toISBN13( $isbnNr )
    {
        $isbnNr = 978 . substr( $isbnNr, 0, 9 );

        $weight13 = 1;
        $checksum13 = 0;
        $val = 0;

        for ( $i = 0; $i < 12; $i++ )
        {
            $val = $isbnNr{$i};
            $checksum13 = $checksum13 + $weight13 * $val;
            $weight13 = ( $weight13 + 2 ) % 4;
        }

        $checkDigit = ( 10 - ( $checksum13 % 10 ) ) % 10;
        $isbnNr .= $checkDigit;

        return $isbnNr;
    }
1105204
public function getIsbn13() : ?string 
    {
        if ( ! $this->hasIsbn13()) {
            $this->setIsbn13($this->getDefaultIsbn13());
        }
        return $this->isbn13;
    }
1329052
public function isValidIsbn(string $isbn) : bool
    {
        return $this->isValidIsbn10($isbn) || $this->isValidIsbn13($isbn);
    }
757478
private static function formatVersion($version)
    {
        $version = str_replace(array('x', 'X', '*'), '0', $version);
        $exp = explode('.', $version);

        if (($size = \count($exp)) < 3) {
            for ($i = $size; $i < 3; ++$i) {
                $exp[] = '0';
            }
        }

        return $exp[0].'.'.$exp[1].'.'.$exp[2];
    }
167099
public static function isValidISBN13($isbn)
    {
        $isbn = self::normalizeISBN($isbn);
        if (strlen($isbn) != 13) {
            return false;
        }
        return
            substr($isbn, 12) == self::getISBN13CheckDigit(substr($isbn, 0, 12));
    }
1142080
public static function php_number_format($number)
    {

        preg_match('/[.,](\d+)$/', $number, $matches);

        $num_decimals = strlen($matches[1]);

        return preg_replace('/[.,]/', '', $number) / pow(10, $num_decimals);
    }
827665
public function identify($isbn)
    {
        if($this->is10($isbn) === true) {
            return 10;
        }
        
        return ($this->is13($isbn) === true ? 13 : false);
    }
621016
public function to10($isbn)
    {
        if(is_string($isbn) === false) {
            throw new Exception('Invalid parameter type.');
        }

        if (strlen($isbn) > 13) {
            $isbn = substr($isbn, 4, -1);
        } else {
            $isbn = substr($isbn, 3, -1);
        }

        return $isbn.$this->checkDigit->make($isbn);
    }
926236
public static function validate($isbn, $type = null)
    {
        if ($type !== null && !in_array($type, [10, 13], true)) {
            throw new \InvalidArgumentException('ISBN type option must be 10 or 13');
        }

        $isbn = str_replace(' ', '', $isbn);
        $isbn = str_replace('-', '', $isbn); // this is a dash
        $isbn = str_replace('‐', '', $isbn); // this is an authentic hyphen

        if ($type === 10) {
            return self::validateIsbn10($isbn);
        }
        if ($type === 13) {
            return self::validateIsbn13($isbn);
        }

        return self::validateIsbn10($isbn) || self::validateIsbn13($isbn);
    }
1027292
public function make($isbn)
    {
        if(is_string($isbn) === false) {
            throw new Exception('Invalid parameter type.');
        }

        $isbn = $this->hyphens->removeHyphens($isbn);
        if (strlen($isbn) === 12 or strlen($isbn) === 13) {
            return $this->make13($isbn);
        } elseif (strlen($isbn) === 9 or strlen($isbn) === 10) {
            return $this->make10($isbn);
        }
        
        return false;
    }
73870
public static function calculateCheckDigit13(string $isbn) : string
    {
        for ($sum = 0, $i = 0; $i < 12; $i++) {
            $sum += $isbn[$i] * (1 + 2 * ($i % 2));
        }

        return (string) ((10 - ($sum % 10)) % 10);
    }
1279589
public function removeHyphens($isbn)
    {
        if(is_string($isbn) === false) {
            throw new Exception('Invalid parameter type.');
        }

        $isbn = str_replace(' ', '', $isbn);
        $isbn = str_replace('-', '', $isbn);
        return $isbn;
    }